I have created a simple SplitView and I'm wondering if I can reuse the code in my <SplitView.Pane>? It's pretty simple, just a few buttons, but I don't want to have to include the same code over and over again on my different pages.
Or is there a way to template the whole SplitView and just modify the <SplitView.Content>on every page? I'd prefer to be able to be able to have the button handlers be global too so that I don't have the same 3 buttons coded in each page .cs file.
What would be the best way to do this?
EDIT: This is for a UWP Windows 10 app.
You can use your own user control to reuse the content of splitview.pane.
UserControl class
Here is an example, my code.. 'FutaLocation' is my usercontrol.
<SplitView x:Name="Splitter" Grid.Row="1"
PanePlacement="Left"
DisplayMode="Inline"
OpenPaneLength="500"
PaneClosed="Splitter_PaneClosed"
PaneClosing="Splitter_PaneClosing"
>
<SplitView.Pane>
<futaviewcontrols:FutaLocation x:Name="futaLocation"/>
</SplitView.Pane>
<Pivot x:Name="directPivot"
If you can make a server control out of it, you can resuse and configure however you like. If this is not possible, you can make a code snippet and then place on page and alter as needed.
Related
I'm not sure of what is the best approach for manipulating controls that are within a sub-frame of a Page. Look:
<Page x:Name="ParentPage">
<!-- ParentPage contains a button. When the button is clicked I would like to select all the items in a ListView that is in the InnerPage Page. -->
<Frame x:Name="SubFrame">
<Page x:Name="InnerPage" />
</Frame>
</Page>
Now InnerPage is actually loaded via C# code because there are actually several different Pages that are loaded into the SubFrame Frame, and so it is hard to do something like the example below. All of the Pages that are loaded into the SubFrame Frame contain the exact same ListView, though.
public sealed partial class ParentPage : Page
{
public ParentPage()
{
InnerPage _InnerPage = SubFrame.Content as InnerPage;
_InnerPage.SelectAllListViewItems();
}
}
Not too clear why you use different inner pages with the same ListView in the SubFrame and what the real effect you want to implement. But you can try to add some different pages in your project, then operate the page in the page's code behind, it would be more easily to manage the pages.
In the parent page, you can use the Frame.Navigate Method to load your child page.
SubFrame.Navigate(typeof(ChildPage));
I have a question like this, I have two pages and have one button in each page, like this mainpage.xaml and second page.xaml, my button in mainpage was disabled with this code: <Button Name="one" IsEnabled="False" Content="Button" />.
Now I want to enable this button with another button that placed in second page.xaml, how I can access the button in mainpage.xaml and make it enable?
I can't access one.isenabled=true in second page, what can I do?
This is not the correct way of doing that.
You can have a global varible to read value from & set enabled/disabled accordingly, send data through URIs (Navigation Contexts) etc. There can be many other solutions too.
At the worst case, take reference variable of the button in code-behind of MainPage.xaml (public static Button b=one;) & access it from another page (MainPage.b.isEnabled=true;). Still, I don't recommend this.
I'm currently dipping my toes into writing Universal Apps for the windows platform, for one of my attempts I'd like to try and make a one of these snazzy new single page apps.
However, I'd like to re-use my code where possible so that I follow DRY principles and don't repeat any code that I don't need to.
As such, I've made a number of User controls (which all work fine on their own) and I'm attempting to embed them inside an Xaml ContentControl ultimately allowing me to swap different ContentControl objects in and out of view at run time.
So far, in my experiments, I have the following code:
XAML:
<ContentControl x:Name="CentralContextHost" Style="{StaticResource ContentControlStyle}">
<!-- The following tag is which ever user control I wish to host -->
<Universal:CentralHubControl/>
</ContentControl>
And the code behind I use to manipulate the above XAML:
public object CurrentControl; // field
if (CurrentControl == null)
CurrentControl = new Profile(); // another usercontrol
var tempswap = CentralContextHost.Content;
CentralContextHost.Content = CurrentControl;
CurrentControl = tempswap;
I would however like to try and make my code much cleaner by using something similar to the binding syntax I've seen used elsewhere by possibly creating my controls as static resources in a dictionary of some kind xaml object, then just dropping a similar deceleration to a bind in the correct position in my xaml to have them display as needed.
The problem I have is that I'm not really sure how to approach solving this problem, or if there is even a way that it can be solved. My idea is to be able to do something similar to the following fictitious bit of code.
<Universal:CentralHubControl x:Key="CentralHub" />
<Universal:Profile x:Key="PersonProfile" />
<ContentControl
x:Name="CentralContextHost"
Grid.RowSpan="2"
Content="{StaticResource CentralHub}"
Style="{StaticResource ContentControlStyle}">
This seems to work in blend but crashes badly when used at run time.
can anyone here see why that might be or what I might be doing wrong?
If you need any more info please ask in the comments and let me know, I'd love to find an answer to both questions here.
I've not played with an app that has everything in one page myself yet. If I did, perhaps I might suggest using a panel as your content host instead of a contentcontrol.
For example, if you were to have a Grid as the root of your layout, which by default it usually is. You can then add your user controls directly to the panel in the code behind by using the following line of code:
rootLayout.Children.Add(AnyUIElement).
Doing things this way may make it possible to create a new instance of the wanted user control and potentially maintain state for it.
For an MVVM style solution, I'll have to play around with the concept.
Is there a specific reason you need to use a contentcontrol that I may not have considered?
I am new to wpf.
Need to show every page with a transition like fade and it should move from
left to right.
suggest the way to acheive this.
Here is the link i tried demo.
Here in this they used an usercontrol in which they are showing the usercontrol with transtions effects.
But my application has more than 15 pages.
So making all pages as user control is not good.
How to achieve this ?
Take a look at the TransitionPresenter control in the WPF Bag of tricks
Basic usage:
<bot:TransitionPresenter Content="{Binding SomeViewModelForWhichYouHaveADataTemplateDefined}">
<bot:TransitionPresenter.Transition>
<bot:FadeTransition Duration="00:00:00.3"/>
</bot:TransitionPresenter.Transition>
</bot:TransitionPresenter>
I have a simple Silverlight application that consists of four pages (XAMLs).
Navigation is done by calling:
//from XamlPageA
this.Content = new XamlPageB();
Is this the right way. I need to have the entries in Browser history so that users can go page to the previous page(s). How can I do it.
You are bypassing the navigation system completely by setting content manually. You would have to implement updating the browser history yourself if you do it that way (certainly possible, but quite tedious).
A simpler approach is to generate a "Silverlight Business Application" project and see how the page navigation is simply handled with hyperlink buttons. All the browser history plumbing is done for you as is the mapping from URL to views.
e.g. A button with NavigateUri="/Home" will cause a view named Home.xaml to load into the navigation:Frame of the MainPage window.
if you look into the navigation:Frame element of MainPage.xaml, you will see a number of UriMapping entries like this:
<uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/>
<uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
They provide the pattern matching to convert from URLs to views.
Hope this helps your project.