Reputation: 2790
Im including the splitview in my app. But i dont know how to fill the content of my splitview. I read i should nest the frame in there. So i have my Mainpage.xaml, and if the user clicks one menue button the content of the splitview should be for example helpandabout.xaml. Or what should i nest in the content property? And how do i replace the content with different pages. I currently just tried to change the visibility of grids if the user presses one button but thats not the philosophy behind this control. Like this:
<Grid x:Name="Grid1" Visibility="Visible"> </Grid>
<Grid Visibility="Collapsed" x:Name="Grid2"> </Grid>
And than the user presses a button at the splitview pane and the code does this:
Grid1.Visibility = Visibility.Collapsed;
Grid2.Visibility = Visibility.Visible;
And i know thats a silly code piece.
Upvotes: 0
Views: 1967
Reputation: 3232
Actually you can replace the complete App standard with an SplitView and Create Navigation etc.
What I did is the following:
1- Learn the Navigation Example from here: uwp navigation example
2.- After you learn how it works, it's has some tricks like the commandbar is outside an appbar, etc. you can extract all the code in a library.
AppShell.xaml, NavMenuItem, NavMenuListView.cs, PageHeader.xaml
3.- Create the following extensions:
public class NavigationExtensions
{
public static void Initialize<T>(List<NavMenuItem> list, NavigationFailedEventHandler OnNavigationFailed, LaunchActivatedEventArgs e)
{
AppShell shell = Window.Current.Content as AppShell;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (shell == null)
{
// Create a AppShell to act as the navigation context and navigate to the first page
shell = new AppShell();
shell.NavigationList = list;
try
{
shell.CurrentItem = list.First(i => i.DestPage == typeof(T));
}
catch
{
}
// Set the default language
shell.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
shell.AppFrame.NavigationFailed += OnNavigationFailed;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
}
// Place our app shell in the current Window
Window.Current.Content = shell;
if (shell.AppFrame.Content == null)
{
// When the navigation stack isn't restored, navigate to the first page
// suppressing the initial entrance animation.
shell.AppFrame.Navigate(typeof(T), e.Arguments, new Windows.UI.Xaml.Media.Animation.SuppressNavigationTransitionInfo());
}
// Ensure the current window is active
Window.Current.Activate();
}
}
4.- Reference all of this in your project and in the App.xaml.cs add
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
NavigationExtensions.Initialize<PersonalView>(Navigation.GetNavigationMenuItems(),OnNavigationFailed,e);
}
where the method is for instance:
public class Navigation
{
public static List<NavMenuItem> GetNavigationMenuItems()
{
var list = new List<NavMenuItem>(
new[]
{
new NavMenuItem()
{
Symbol = Symbol.Contact,
Label = "Personal",
DestPage = typeof(PersonalView)
},
new NavMenuItem()
{
Symbol = Symbol.World,
Label = "Countries",
DestPage = typeof(CountriesView)
},
new NavMenuItem()
{
Symbol = Symbol.Setting,
Label = "Settings",
DestPage = typeof(SettingsView)
},
});
return list;
}
}
Upvotes: 0