Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
XAML replacement for MessageBox.Show - allows centering on parent
YesNoWindow message =
new YesNoWindow("Confirm Delete", "Are you sure you want to delete this account?");
message.Owner = Window.GetWindow(this);
message.ShowDialog();
if (message.ClickedYes)
{
AppViewModel.GetInstance().DeleteAccount(selectedAccount);
}
<Window x:Class="AccountManager.Windows.YesNoWindow"
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"
mc:Ignorable="d"
FontSize="11pt"
WindowStartupLocation="CenterOwner"
ResizeMode="NoResize"
Title="YesNoWindow"
SizeToContent="WidthAndHeight">
<Grid Margin="5,5,5,5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="10"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0"
Grid.ColumnSpan="2"
x:Name="Message"/>
<Button Grid.Row="2" Grid.Column="0"
Content="No"
Style="{StaticResource SmallButton}"
Width="75"
HorizontalAlignment="Left"
Click="No_OnClick"/>
<Button Grid.Row="2" Grid.Column="1"
Content="Yes"
Style="{StaticResource SmallButton}"
Width="75"
HorizontalAlignment="Right"
Click="Yes_OnClick"/>
</Grid>
</Window>
using System.Windows;
namespace AccountManager.Windows
{
public partial class YesNoWindow : Window
{
public bool ClickedYes { get; private set; }
public YesNoWindow(string title, string message)
{
InitializeComponent();
Title = title;
Message.Content = message;
}
private void Yes_OnClick(object sender, RoutedEventArgs e)
{
ClickedYes = true;
Close();
}
private void No_OnClick(object sender, RoutedEventArgs e)
{
ClickedYes = false;
Close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.