Frances83

Hi all,

I have a window containing a Frame:

<Window x:Class="MyProj.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MyProj - MainWindow"
Height="600" Width="600"
ResizeMode="NoResize"
>
<Frame Name="frame" NavigationUIVisibility="Hidden" />
</Window>

In the frame I host another page:

frame.Navigate(new BasicDetails());

which looks like this:

<Page x:Class="MyProj.BasicDetails"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="65*" />
<RowDefinition Height="20*" />
<RowDefinition Height="15*" />
</Grid.RowDefinitions>

<Border Grid.Row="0">

</Border>

<Border Grid.Row="1">
<TextBlock Name="txtHelpText" />
</Border>

<Border Grid.Row="2">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<StackPanel.Resources>
<Style TargetType="{x:Type Button}">
<EventSetter Event="Click" Handler="OnButtonClicked" />
</Style>
</StackPanel.Resources>

<Button Name="btnBack" Content="_Back" IsEnabled="False" />
<Button Name="btnNext" Content="_Next" />
<Button Name="btnCancel" Content="_Cancel" />

</StackPanel>
</Border>

</Grid>
</Page>

I open the MainWindow as a modal dialog:

MainWindow mainWindow = new MainWindow();
mainWindow.ShowDialog();


Now what I want to do, is that when the user clicks the 'Cancel' button, the dialog closes. How can I find MainWindow from BasicDetails


Thanks,
Frances


Re: Windows Presentation Foundation (WPF) Closing a modal dialog

SerialSeb

from BasicDetails, call in the code behind:

Window.GetWindow(this).Close();

although using ApplicationCommands.Close as a Command on a button may work just fine too.