/SampleCallingCode.cs Secret
Created
May 4, 2020 21:36
Star
You must be signed in to star a gist
XAML replacement for MessageBox.Show - allows centering on parent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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