PageFunction<T>进行导航比较符合逻辑。简单的使用如下。
例如:有两个页面,Page1和Page2
Page1:
那么在实际使用中,Page1最好不要是带参数的构造器,如果是那么Page2就无法返回;
向Page2导航时也不能用线程,同样会造成无法返回。
因此在项目中需要注意。
例如:有两个页面,Page1和Page2
Page1:
<PageFunction x:Class="TestFounctionPage.Page1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:sys="clr-namespace:System;assembly=mscorlib" x:TypeArguments="sys:Boolean" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" Title="Page1"> <Grid> <TextBlock Height="21" HorizontalAlignment="Left" Margin="88,132,0,0" Name="tb" Text="Page1" VerticalAlignment="Top" Width="77" /> <Button Content="下一页" Height="23" HorizontalAlignment="Left" Margin="75,171,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" /> </Grid> </PageFunction>
public partial class Page1 : PageFunction<Boolean> { public Page1() { InitializeComponent(); } //public Page1(int test) //{ // InitializeComponent(); //} private void button1_Click(object sender, RoutedEventArgs e) { GuidPage(); //BackgroundWorker worker = new BackgroundWorker(); //worker.DoWork += (o, p) => // { // GuidPage(); // }; //worker.RunWorkerCompleted += (o, p) => // { // }; //worker.RunWorkerAsync(); } void Page2_Return(object sender, ReturnEventArgs<bool> e) { } void GuidPage() { Page2 page2 = new Page2(); page2.Return += new ReturnEventHandler<bool>(Page2_Return); this.NavigationService.Navigate(page2); } }
Page2: <PageFunction x:Class="TestFounctionPage.Page2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:sys="clr-namespace:System;assembly=mscorlib" x:TypeArguments="sys:Boolean" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" Title="Page2"> <Grid> <TextBlock Height="23" HorizontalAlignment="Left" Margin="96,118,0,0" Name="textBlock1" Text="Page2" VerticalAlignment="Top" Width="79" /> <Button Content="返 回" Height="23" HorizontalAlignment="Left" Margin="82,174,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" /> </Grid> </PageFunction>
public partial class Page2 : PageFunction<Boolean> { public Page2() { InitializeComponent(); } private void button2_Click(object sender, RoutedEventArgs e) { this.OnReturn(new ReturnEventArgs<bool>(true)); } }
那么在实际使用中,Page1最好不要是带参数的构造器,如果是那么Page2就无法返回;
向Page2导航时也不能用线程,同样会造成无法返回。
因此在项目中需要注意。
测试代码如下:
http://download.youkuaiyun.com/detail/yysyangyangyangshan/5168833