Skip to content

Commit

Permalink
Update dialog to use built in styles, content, and buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
jwmsft committed Jul 9, 2021
1 parent f1154f2 commit e58a1ce
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions ContosoApp/Views/OrderDetailPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected async override void OnNavigatingFrom(NavigatingCancelEventArgs e)
var saveDialog = new SaveChangesDialog()
{
Title = $"Save changes to Invoice # {ViewModel.InvoiceNumber.ToString()}?",
Message = $"Invoice # {ViewModel.InvoiceNumber.ToString()} " +
Content = $"Invoice # {ViewModel.InvoiceNumber.ToString()} " +
"has unsaved changes that will be lost. Do you want to save your changes?"
};

Expand Down Expand Up @@ -184,7 +184,7 @@ private async void RevertButton_Click(object sender, RoutedEventArgs e)
var saveDialog = new SaveChangesDialog()
{
Title = $"Save changes to Invoice # {ViewModel.InvoiceNumber.ToString()}?",
Message = $"Invoice # {ViewModel.InvoiceNumber.ToString()} " +
Content = $"Invoice # {ViewModel.InvoiceNumber.ToString()} " +
"has unsaved changes that will be lost. Do you want to save your changes?"
};
await saveDialog.ShowAsync();
Expand Down
15 changes: 13 additions & 2 deletions ContosoApp/Views/SaveChangesDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,21 @@
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"
xmlns:local="using:Contoso.App.Views"
Title="Save changes?"
Content="You have unsaved changes that will be lost. Would you like to save your changes?"
PrimaryButtonText="Save"
SecondaryButtonText="Don't save"
CloseButtonText="Cancel"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
SecondaryButtonClick="ContentDialog_SecondaryButtonClick"
CloseButtonClick="ContentDialog_CloseButtonClick"
mc:Ignorable="d">
<ContentDialog.Resources>
<Style TargetType="local:SaveChangesDialog" BasedOn="{StaticResource DefaultContentDialogStyle}"/>
</ContentDialog.Resources>

<StackPanel
<!--<StackPanel
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<TextBlock
Expand Down Expand Up @@ -59,6 +70,6 @@
Click="cancelButton_Click"
Content="Cancel" />
</Grid>
</StackPanel>
</StackPanel>-->

</ContentDialog>
20 changes: 7 additions & 13 deletions ContosoApp/Views/SaveChangesDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,30 @@ public SaveChangesDialog()
/// <summary>
/// Gets or sets the user's choice.
/// </summary>
public SaveChangesDialogResult Result { get; set; } = SaveChangesDialogResult.Cancel;
public SaveChangesDialogResult Result { get; private set; } = SaveChangesDialogResult.Cancel;

/// <summary>
/// Gets or sets the display message.
/// Occurs when the user chooses to save.
/// </summary>
public string Message { get; set; } = "You have unsaved changes that will be lost. " +
"Would you like to save your changes?";

/// <summary>
/// Fired when the user chooses to save.
/// </summary>
private void yesButton_Click(object sender, RoutedEventArgs e)
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
Result = SaveChangesDialogResult.Save;
Hide();
}

/// <summary>
/// Fired when the user chooses to discard changes.
/// Occurs when the user chooses to discard changes.
/// </summary>
private void noButton_Click(object sender, RoutedEventArgs e)
private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
Result = SaveChangesDialogResult.DontSave;
Hide();
}

/// <summary>
/// Fired when the user chooses to cancel the operation that triggered the event.
/// Occurs when the user chooses to cancel the operation that triggered the event.
/// </summary>
private void cancelButton_Click(object sender, RoutedEventArgs e)
private void ContentDialog_CloseButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
Result = SaveChangesDialogResult.Cancel;
Hide();
Expand Down

0 comments on commit e58a1ce

Please sign in to comment.