c# - WPF Navigate to other page -
i want navigate between pages
public partial class mainwindow : window { public mainwindow() { initializecomponent(); } private void routeitems(object sender, routedeventargs e) { navigationservice nav = navigationservice.getnavigationservice(this); nav.navigate(new itemspage()); } }
getnavigationservice returns null
<window x:class="special.mainwindow" name="window" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:special" mc:ignorable="d" title="mainwindow" windowstate="maximized"> <button content="go" click="routeitems"/> </window>
i don't want use other method (changing content).
edit
this.navigationservice undefined
you need to, first add frame
xaml:
<grid > <grid.rowdefinitions> <rowdefinition height="*"/> <rowdefinition height="auto"/> </grid.rowdefinitions> <frame x:name="mainframe"></frame> <button content="go" click="routeitems" grid.row="1"/> </grid>
then after add xaml pages, use mainframe navigate:
private void routeitems(object sender, routedeventargs e) { mainframe.navigationservice.navigate(new uri("page1.xaml", urikind.relativeorabsolute)); }
Comments
Post a Comment