WPF-008:使用PageFunction导航不能使用带参构造和线程导航

PageFunction<T>进行导航比较符合逻辑。简单的使用如下。
例如:有两个页面,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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值