MainWindow가있는 간단한 WPF 응용 프로그램이 있습니다. 코드에서 언로드 된 이벤트를 설정하십시오. 시작 URL로 MainWindow
을 설정하십시오. 창을 닫으면 언로드되지 않습니다. 한 번의 클릭으로 두 번째 창 (NotMainWindow
)을 만듭니다.이상한 언로드 동작 - WPF 창
버튼 클릭 이벤트에서 MainWindow를 호출하십시오. 닫기 MainWindow
및 언로드가 트리거됩니다. 왜 행동의 차이가 있습니까? 내가 뭘 하려는지, 어떤 종류의 언로드 된 이벤트를 얻으려면 한 번만?
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Unloaded="Main_Unloaded">
<Grid>
</Grid>
</Window>
private void Main_Unloaded(object sender, RoutedEventArgs e)
{
}
<Window x:Class="WpfApplication2.NotMainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="NotMainWindow" Height="300" Width="300">
<Grid>
<Button Content="Show Main" Height="25" Margin="10" Width="70" Click="Button_Click" />
</Grid>
</Window>
private void Button_Click(object sender, RoutedEventArgs e)
{
MainWindow win = new MainWindow();
win.Show();
}
<Application x:Class="WpfApplication2.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="NotMainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
닫혀있을 때 호출되지 않습니다. 그것이 문제입니다. 물론로드시 호출되지 않습니다! : P – Harsha
@Blachshma - 혼란을 없애기 위해 질문을 수정했습니다. – Harsha
MainWindow를 만든 다음 즉시 닫고 언로드되지 않았다고 말하는 것입니까? – Blachshma