Dialogs can be closed by updating the IsOpen property, using commands, or via the DialogSession.
- XAML/Binding: Set
IsOpen="False". - Commands: Bind to the
CloseDialogCommand on the DialogHost. The command parameter passed to this command will be returned as the result of the Show() call. - DialogSession: Access the session via the
DialogOpenedEventArgs in an opened event, or by using DialogHost.GetDialogSession("Identifier") to close it programmatically.
<!-- Using CloseDialogCommand inside the dialog content -->
<Button Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dialogHost:DialogHost}, Path=CloseDialogCommand}" CommandParameter="Success" />
// Closing via DialogOpenedEventArgs session
var result = await DialogHost.Show(myContent, delegate(object sender, DialogOpenedEventArgs args)
{
args.Session.Close(false);
});
// Closing via Identifier
DialogHost.GetDialogSession("MyDialogIdentifier")?.Close(false);