I have a problem with Pivot control. How can I insert xaml page with content to Pivot item? Is it even possible?
When I’m storing everything in one file it’s really hard to take control over my own application layout.
I want something like this:
on main page should be pivot control with items.
content of those items should be in separated xaml files (there is no dependency between pages)
Add correct namespace to Page:
xmlns:view="clr-namespace:YourApp.Controls"
and in Pivot:
<Pivot>
<PivotItem Name="first">
<view:FirstUserControl DataContext="{Binding YourViewModel}"/>
</PivotItem>
</Pivot>
And in view namespace you need to create a User Control. The link is about WPF but in WP7 there is the same system.
Also, you can create Custom Control from PivotItem.
Related
I have multiple window files and i want to merge my Xaml files(window) into a Tab control in a MVVM Pattern.
Each item Tab will represents a Xaml file.
i need something like this:
<TabControl >
<TabItem>
<local:FirstView></local:FirstView>
</TabItem>
<TabItem>
<local:SecondView></local:SecondView>
</TabItem>
</TabControl>
but i get this Error:
"Window must be the root of the tree. Cannot add Window as a child of Visual."
I have seen many topics like this but they use user control or they use a single view with multiple View Model.
Is there any way to import window(xaml) into tab control?
And another important thing, i want to have a button like Cancel, Pushing Cancel means we have to go back one level(go to another tab Item).
view model is not aware of view, so how can i navigate through them?
Is there any way to import window(xaml) into tab control?
No, there isn't. A System.Windows.Window cannot be a child of another System.Windows.Window.
The contents of the tab items should be defined as UserControls.
You should just be able to move the contents of your windows to the user controls.
i want to use a usercontrol, (set of TextBlock & Combobox). I want 3 instance of it in the same, page. So how can I define such usercontrol in the same page's xaml? need to use page resource? or anything else?
Within Visual Studio you can define UserControls by going to Project --> Add New Item and selecting User Control. After defining it there you can then add a reference to it in the XAML of the page you want to use it in. You do this by adding a something along the lines of the following to the root tag of your page.
<common:LayoutAwarePage
...
xmlns:CustomControlName="using:CustomControlNamespace"
...>
If you have to do it in the same XAML document, I guess you could define the control in the pages resources
<Page.Resources>
<UserControl x:Name="CustomControl">
...
</UserControl>
</Page.Resources>
Personally I would define a UserControl in a separate file. It separates things out and Visual Studio also gives you some basics to work from.
When my app is snapped displaying a GridView isn't the best way to present the information. I want to present it in a ListView instead. I also want to change the item template as well.
I currently have a UserControl that accepts the DataContext as the item template so I can simply create a new view and use that instead and it should work. So I'm basically looking to swap local:NormalDetailView with local:SnappedDetailView
Originally I thought about having both the ListView and GridView in there at the same time and adjusting the visibility based on snapped mode. But I had doubts about the performance about this technique.
Lastly, this is a LayoutAwarePage so I do have all that XAML stuff at the bottom about VisualStateManager.VisualStateGroups etc.
<GridView x:Name="GalleryGridView"ItemsSource="{Binding ListOfItems}">
<GridView.ItemTemplate>
<DataTemplate>
<local:NormalDetailView VerticalAlignment="Center" Width="250" Height="250" DataContext="{Binding}"/>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
The performance is just fine if you use both a gridview and a listview, and adjust visibility depending on view state. This is exactly what the "split-application" template in Visual Studio does.
Just generate an app based on this template and take a look at ItemsPage.xaml and ItemsPage.xaml.cs. The other templates may also do this, but I haven't used them so I don't know for sure.
So I have a Panorama control and the PanoramaItems are programmatically added to the control using the following template.
<UserControl>
<Grid x:Name="LayoutRoot">
<controls:PanoramaItem Name="sitePanoramaItem" Header="{Binding Name}">
<Controls:DockPanel VerticalAlignment="Stretch">
<StackPanel Orientation="Horizontal" Margin="0,10,0,0" Controls:DockPanel.Dock="Top">
<Image Source="../Images/action.png" Width="64" />
<TextBlock Text="{Binding Stats, Mode=TwoWay}" FontSize="45" Margin="15,0,0,0" />
</StackPanel>
<Grid x:Name="graphCanvas" HorizontalAlignment="Stretch" Margin="10,10,10,10"> </Grid>
</Controls:DockPanel>
</controls:PanoramaItem>
</Grid>
</UserControl>
When I click on graphCanvas what I'd like to do is sorta pop the graphCanvas out and display that fullscreen then when I click again restore it to where it was. I've been all over this site and Google and can't find anything similar to what I'm looking for.
I would still like to maintain the Panorama control functionality so that the graphCanvas is still the only one visible but you can cycle through them. Currently I have it sorta working in that I remove the Grid from the DockPanel and put it directly in the LayoutRoot while making the sitePanoramaItem collapsed. However, it's not fullscreen as the Panorama name is still visible (I guess I could hide that as well...) When I put the graphCanvas back int he DockPanel the size of the canvas is all screwed up.
I was hoping there was a simpler way.
Is it even possible?
It is possible to create the UI you describe but it's not going to be simple. You're on the right track with removing it in code and adding it the LayoutRoot and making the Panorama hidden. However you would have to code the scrolling behavior yourself and that is going to be quite tricky - especially making it feel the way to panorama does.
One trick you could try is actually layer a PivotControl on top of your Panorama and have it be collapsed by default. Also edit it's template to remove all default content eg: remove the header control, set margins to 0, etc). Then when you want to go full screen you can remove all the graphCanvases from the Panorama items and and add them to new PivotItems in the PivotControl. Then hide the Panorama and show the Pivot. This will give you scrolling capability for free and the illusion of full screen.
Having said all that I'm not sure I would recommend this. The more common approach would be to simply be to navigate to another page when the user selects an item and handle the full screen aspects there (possibly using the Pivot control again for scrolling). And when you want to leave "fullscreen" mode simply navigate back to the first page. Handling Tombstoning of the fullscreen state will be much easier with this approach for one thing.
You can try making the graphCanvas a Page and putting it in a different XAML. Then add a frame (name it InnerFrame for example) in the same place where you have the graphCanvas right now and navigate to that page with InnerFrame. When the frame is clicked, you navigate with the RootFrame of the app to your graphCanvas page. When you decide to close it, just navigate back with the RootFrame.
Hope it's clear enough :)
Edit:
Navigation in WP7 works very similar as the standard navigation in Silverlight 4, but it's a bit more restrictive. Just throw a PhoneApplicationFrame in your XAML like this:
<phone:PhoneApplicationFrame x:Name="Frame" />
This is basically the same as a Silverlight frame. All the pages you create inherit from PhoneApplicationPage by default, so they can be showed in a frame without any changes.
Your whole application actually runs on a PhoneApplicationFrame. If you take a look at your App class you will see this:
public PhoneApplicationFrame RootFrame { get; private set; }
Here's the MSDN documentation for the navigation system on WP7
I am trying to creating a combobox with checkboxes on each line to allow multiple selecting. Would this be better as a User Control or Custom Control?
I haven't created a control before so just looking for a little advice on what direction I need to head.
Thanks.
UserControl (Composition)
Composes multiple existing controls into a reusable "group"
Consists of a XAML and a code behind file
Cannot be styled/templated
Derives from UserControl
CustomControl (Extending an existing control)
Extends an existing control with additional features
Consists of a code file and a default style in Themes/Generic.xaml
Can be styled/templated
The best approach to build a control library
In your case, I think UserControl would be better; here's an example for you:
<CheckBox Content="Property" IsChecked="{Binding Path=SomeProperty}" />
<ComboBox IsEnabled="{Binding Path=Enabled}" />
I would say use a datatemplate.
Like this: Looking for a WPF ComboBox with checkboxes
It's a lot more simple than trying to create your own control. :)