在 WPF 项目中,我使用 a导航到 a PageFunction
,它是. 问题是不返回调用。事实上,调用 OnReturn(...) 在抛出一个说法:Window
Frame
Window
PageFunction
Window
PageFunction
InvalidOperationException
PageFunction 的 NavigationWindow 已经关闭或导航到不同的内容
为什么会抛出异常?
这是一些显示问题的示例代码:
主窗口.xaml
<Window x:Class="WpfApplication3.MainWindow"
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:WpfApplication3"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Frame x:Name="frame" />
MainWindow 代码背后:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var myPageFunction = new MyPageFunction();
myPageFunction.Return += MyPageFunction_Return;
frame.Navigate(myPageFunction);
}
private void MyPageFunction_Return(object sender, ReturnEventArgs<string> e)
{
// Doesn't get here!
}
}
PageFunction.xaml
<PageFunction
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
x:Class="WpfApplication3.MyPageFunction"
x:TypeArguments="sys:String"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApplication3"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="MyPageFunction">
<Grid>
<Button x:Name="btnReturn" Click="btnReturn_Click" Content="Return"/>
</Grid></PageFunction>
后面的PageFunction代码:
public partial class MyPageFunction : PageFunction<String>
{
public MyPageFunction()
{
InitializeComponent();
}
private void btnReturn_Click(object sender, RoutedEventArgs e)
{
// THIS THROWS EXCEPTION!
OnReturn(new ReturnEventArgs<string>("return"));
}
}