Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,98 @@ private async Task OnOpenCustomMessageBox(object sender)

_ = await uiMessageBox.ShowDialogAsync();
}

[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "relay command")]
[RelayCommand]
private async Task OnOpenThreeButtonMessageBox(object sender)
{
var uiMessageBox = new Wpf.Ui.Controls.MessageBox
{
Title = "Confirmation",
Content = "Do you want to save your changes before closing?",
PrimaryButtonText = "Save",
SecondaryButtonText = "Don't Save",
CloseButtonText = "Cancel",
DefaultFocusedButton = Wpf.Ui.Controls.MessageBoxButton.Secondary,
};

var result = await uiMessageBox.ShowDialogAsync();
_ = MessageBox.Show($"You selected: {result}", "Result");
}

[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "relay command")]
[RelayCommand]
private async Task OnOpenMessageBoxWithFocusableContent(object sender)
{
var textBox = new System.Windows.Controls.TextBox
{
Text = "Type something here...",
Margin = new System.Windows.Thickness(0, 8, 0, 0),
};

var uiMessageBox = new Wpf.Ui.Controls.MessageBox
{
Title = "Input Required",
Content = new System.Windows.Controls.StackPanel
{
Children =
{
new System.Windows.Controls.TextBlock
{
Text = "Please enter your name:",
TextWrapping = System.Windows.TextWrapping.Wrap,
},
textBox,
},
},
PrimaryButtonText = "OK",
SecondaryButtonText = "Cancel",
DefaultFocusedButton = Wpf.Ui.Controls.MessageBoxButton.Primary,
};

var result = await uiMessageBox.ShowDialogAsync();
if (result == Wpf.Ui.Controls.MessageBoxResult.Primary)
{
_ = MessageBox.Show($"Hello, {textBox.Text}!", "Greeting");
}
}

[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "relay command")]
[RelayCommand]
private async Task OnOpenMessageBoxWithIcons(object sender)
{
var uiMessageBox = new Wpf.Ui.Controls.MessageBox
{
Title = "Warning",
Content = "This action cannot be undone. Are you sure you want to continue?",
PrimaryButtonText = "Yes, Continue",
SecondaryButtonText = "No, Cancel",
PrimaryButtonIcon = new Wpf.Ui.Controls.SymbolIcon
{
Symbol = Wpf.Ui.Controls.SymbolRegular.Warning24,
},
DefaultFocusedButton = Wpf.Ui.Controls.MessageBoxButton.Secondary,
};

_ = await uiMessageBox.ShowDialogAsync();
}

[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "relay command")]
[RelayCommand]
private async Task OnOpenMessageBoxWithAutoFocus(object sender)
{
// DefaultFocusedButton is not set, so focus will automatically be set to primaryButton
// when no button has focus and no non-button control has focus
var uiMessageBox = new Wpf.Ui.Controls.MessageBox
{
Title = "Auto Focus",
Content = "This MessageBox will automatically set focus to the primary button when no button or non-button control has focus.",
PrimaryButtonText = "OK",
SecondaryButtonText = "Cancel",
// DefaultFocusedButton is intentionally not set
};

var result = await uiMessageBox.ShowDialogAsync();
_ = MessageBox.Show($"You selected: {result}", "Result");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,33 @@
CommandParameter="{Binding RelativeSource={RelativeSource Self}, Mode=OneWay}"
Content="Open custom MessageBox" />
</controls:ControlExample>

<controls:ControlExample Margin="0,36,0,0" HeaderText="Three Button MessageBox. (Default Focus: Secondary Button)">
<Button
Command="{Binding ViewModel.OpenThreeButtonMessageBoxCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:MessageBoxPage}, Mode=OneWay}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}, Mode=OneWay}"
Content="Open three button MessageBox" />
</controls:ControlExample>

<controls:ControlExample Margin="0,36,0,0" HeaderText="MessageBox with Focusable Content. (Default Focus: Primary Button)">
<Button
Command="{Binding ViewModel.OpenMessageBoxWithFocusableContentCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:MessageBoxPage}, Mode=OneWay}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}, Mode=OneWay}"
Content="Open MessageBox with TextBox" />
</controls:ControlExample>

<controls:ControlExample Margin="0,36,0,0" HeaderText="MessageBox with Icons. (Default Focus: Secondary Button)">
<Button
Command="{Binding ViewModel.OpenMessageBoxWithIconsCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:MessageBoxPage}, Mode=OneWay}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}, Mode=OneWay}"
Content="Open MessageBox with icon" />
</controls:ControlExample>

<controls:ControlExample Margin="0,36,0,0" HeaderText="MessageBox with Auto Focus. (Default Focus: Primary Button - automatically set when no button or non-button control has focus)">
<Button
Command="{Binding ViewModel.OpenMessageBoxWithAutoFocusCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:MessageBoxPage}, Mode=OneWay}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}, Mode=OneWay}"
Content="Open MessageBox with auto focus" />
</controls:ControlExample>
</StackPanel>
</Page>
Loading
Loading