ConnectionFailedDialog -> Dialog for Success and Error Messages with heading, message and buttons/actions

This commit is contained in:
Patrick Hellebrand
2021-09-23 08:59:22 +02:00
parent 2b6d871a30
commit 44ef2f4cd2
7 changed files with 132 additions and 56 deletions

View File

@@ -1,26 +0,0 @@
using PolyChat.Models;
using PolyChat.Util;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace PolyChat.Views
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class ConnectionFailedDialog : ContentDialog
{
public ConnectionFailedDialog(string message)
{
this.InitializeComponent();
textError.Text = message;
}
}
}

View File

@@ -1,17 +1,20 @@
<ContentDialog x:Class="PolyChat.Views.ConnectionFailedDialog"
<ContentDialog x:Class="PolyChat.Views.Dialog"
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:local="using:PolyChat.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="MessageDialog"
Title="Connection Failed"
PrimaryButtonText="Retry"
SecondaryButtonText="Abort"
Title="Header"
PrimaryButtonText="Primary"
PrimaryButtonClick="OnPrimaryButtonClick"
SecondaryButtonText="Secondary"
SecondaryButtonClick="OnSecondaryButtonClick"
mc:Ignorable="d">
<StackPanel>
<TextBlock Text="Message:" Foreground="{ThemeResource SystemColorDisabledTextColor}" Margin="0 0 0 8"/>
<TextBlock x:Name="textError" Foreground="{ThemeResource SystemErrorTextColor}"/>
<TextBlock x:Name="textError" Foreground="{ThemeResource SystemErrorTextColor}" Visibility="Collapsed"/>
<TextBlock x:Name="textSuccess" Foreground="{ThemeResource SystemAccentColor}" Visibility="Collapsed"/>
</StackPanel>
</ContentDialog>

View File

@@ -0,0 +1,70 @@
using PolyChat.Models;
using PolyChat.Util;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using Windows.Foundation;
using Windows.UI.Core;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace PolyChat.Views
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class Dialog : ContentDialog
{
public const string TYPE_ERROR = "error";
public const string TYPE_SUCCESS = "success";
private Action Primary;
private Action Secondary;
public Dialog(string type, string header, string message, DialogButton primary, DialogButton secondary)
{
this.InitializeComponent();
Title = header;
setType(type, message);
PrimaryButtonText = primary.Text;
SecondaryButtonText = secondary.Text;
// TODO: use event handlers and asign actions here
Primary = primary.Action;
Secondary = secondary.Action;
// show
ShowDialogAsync();
}
private void setType(string type, string message)
{
switch (type)
{
case TYPE_ERROR:
textError.Text = message;
textError.Visibility = Visibility.Visible;
break;
case TYPE_SUCCESS:
textSuccess.Text = message;
textSuccess.Visibility = Visibility.Visible;
break;
}
}
private async void ShowDialogAsync()
{
await ShowAsync();
}
private void OnPrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
Primary();
}
private void OnSecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
Secondary();
}
}
}