2017-01-15 2 views
1

WPF 프로젝트에서 Window의 내용 인 Frame을 사용하여 Window에서 PageFunction으로 이동합니다. 문제는 PageFunction이므로 Window으로 돌아 오지 않습니다. 실제로 PageFunction에서 OnReturn (...)을 호출하면 InvalidOperationException이 표시되며 'PageFunction의 NavigationWindow가 이미 닫혔거나 다른 콘텐츠로 이동했습니다'라고 표시됩니다.WPF : 왜 PageFunction이 호출 창으로 돌아 가지 않습니까?

왜 예외가 발생합니까?

사전 도움을 주셔서 감사드립니다.

MainWindow.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

,691,363 여기

문제를 보여줍니다 일부 샘플 코드 (210)
<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")); 
    } 
} 

답변