From e772bdee77d7e87dbbe0165d913855c043abae14 Mon Sep 17 00:00:00 2001 From: Maxhy Date: Thu, 23 May 2024 10:55:39 +0200 Subject: [PATCH] Add Error icon on Snackbar error messages Add WpfAppDemo application --- WpfApp.sln | 6 ++++ WpfApp/MainWindow.xaml | 8 +++-- WpfApp/SnackbarHelper.cs | 15 +++++++-- WpfApp/WpfApp.csproj | 2 +- WpfAppDemo/App.xaml | 15 +++++++++ WpfAppDemo/App.xaml.cs | 18 +++++++++++ WpfAppDemo/AssemblyInfo.cs | 10 ++++++ WpfAppDemo/DemoAppInfo.cs | 37 +++++++++++++++++++++++ WpfAppDemo/Domain/HomeControlViewModel.cs | 31 +++++++++++++++++++ WpfAppDemo/HomeControl.xaml | 15 +++++++++ WpfAppDemo/HomeControl.xaml.cs | 15 +++++++++ WpfAppDemo/WpfAppDemo.csproj | 15 +++++++++ 12 files changed, 182 insertions(+), 5 deletions(-) create mode 100644 WpfAppDemo/App.xaml create mode 100644 WpfAppDemo/App.xaml.cs create mode 100644 WpfAppDemo/AssemblyInfo.cs create mode 100644 WpfAppDemo/DemoAppInfo.cs create mode 100644 WpfAppDemo/Domain/HomeControlViewModel.cs create mode 100644 WpfAppDemo/HomeControl.xaml create mode 100644 WpfAppDemo/HomeControl.xaml.cs create mode 100644 WpfAppDemo/WpfAppDemo.csproj diff --git a/WpfApp.sln b/WpfApp.sln index 18df378..3caff2d 100644 --- a/WpfApp.sln +++ b/WpfApp.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.5.33516.290 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfApp", "WpfApp\WpfApp.csproj", "{E29065B9-9FFC-4D05-8B0B-FB1B8EB440A4}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfAppDemo", "WpfAppDemo\WpfAppDemo.csproj", "{31F019D6-B05B-47CA-8D4C-F1D54B971C50}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {E29065B9-9FFC-4D05-8B0B-FB1B8EB440A4}.Debug|Any CPU.Build.0 = Debug|Any CPU {E29065B9-9FFC-4D05-8B0B-FB1B8EB440A4}.Release|Any CPU.ActiveCfg = Release|Any CPU {E29065B9-9FFC-4D05-8B0B-FB1B8EB440A4}.Release|Any CPU.Build.0 = Release|Any CPU + {31F019D6-B05B-47CA-8D4C-F1D54B971C50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {31F019D6-B05B-47CA-8D4C-F1D54B971C50}.Debug|Any CPU.Build.0 = Debug|Any CPU + {31F019D6-B05B-47CA-8D4C-F1D54B971C50}.Release|Any CPU.ActiveCfg = Release|Any CPU + {31F019D6-B05B-47CA-8D4C-F1D54B971C50}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WpfApp/MainWindow.xaml b/WpfApp/MainWindow.xaml index d1af7e7..28e3d22 100644 --- a/WpfApp/MainWindow.xaml +++ b/WpfApp/MainWindow.xaml @@ -21,6 +21,9 @@ FontFamily="{DynamicResource MaterialDesignFont}" Loaded="Window_Loaded"> + + + @@ -170,8 +173,9 @@ + Grid.Row="1" + ActionButtonStyle="{StaticResource MaterialDesignSnackbarActionDarkButton}" + MessageQueue="{materialDesign:MessageQueue}" /> diff --git a/WpfApp/SnackbarHelper.cs b/WpfApp/SnackbarHelper.cs index 5cd9db8..1ce864f 100644 --- a/WpfApp/SnackbarHelper.cs +++ b/WpfApp/SnackbarHelper.cs @@ -37,12 +37,23 @@ public static void EnqueueError(ISnackbarMessageQueue? queue, Exception? ex, str message = "An error occured."; } - EnqueueMessage(queue, message); + var panel = new DockPanel(); + var errorIcon = new PackIcon() { Kind = PackIconKind.ExclamationThick }; + DockPanel.SetDock(errorIcon, Dock.Left); + panel.Children.Add(errorIcon); + panel.Children.Add(new TextBlock() { Text = message, Margin = new Thickness(5, 0, 0 ,0), TextWrapping = TextWrapping.Wrap }); + + EnqueueMessage(queue, panel); + } + + public static void EnqueueMessage(ISnackbarMessageQueue? queue, PackIconKind icon, object message) + { + queue?.Enqueue(message, new PackIcon { Kind = icon }, (object? _) => { }, null, false, true, TimeSpan.FromSeconds(5)); } public static void EnqueueMessage(ISnackbarMessageQueue? queue, object message) { - queue?.Enqueue(message, new PackIcon { Kind = PackIconKind.CloseBold }, (object? _) => { }, null, false, true, TimeSpan.FromSeconds(5)); + EnqueueMessage(queue, PackIconKind.CloseBold, message); } public static void HandlePreviewMouseWheel(object sender, MouseWheelEventArgs e) diff --git a/WpfApp/WpfApp.csproj b/WpfApp/WpfApp.csproj index 6a7d0a8..d7436ea 100644 --- a/WpfApp/WpfApp.csproj +++ b/WpfApp/WpfApp.csproj @@ -6,7 +6,7 @@ true True Leosac.$(AssemblyName) - 1.19.0 + 1.20.0 Leosac WpfApp Library C# Library components/helpers for Leosac branded Wpf applications . Leosac SAS diff --git a/WpfAppDemo/App.xaml b/WpfAppDemo/App.xaml new file mode 100644 index 0000000..f929572 --- /dev/null +++ b/WpfAppDemo/App.xaml @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/WpfAppDemo/App.xaml.cs b/WpfAppDemo/App.xaml.cs new file mode 100644 index 0000000..7c4e0f7 --- /dev/null +++ b/WpfAppDemo/App.xaml.cs @@ -0,0 +1,18 @@ +using Leosac.SharedServices; +using System.Configuration; +using System.Data; +using System.Windows; + +namespace WpfAppDemo +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + public App() + { + LeosacAppInfo.Instance = new DemoAppInfo(); + } + } +} diff --git a/WpfAppDemo/AssemblyInfo.cs b/WpfAppDemo/AssemblyInfo.cs new file mode 100644 index 0000000..b0ec827 --- /dev/null +++ b/WpfAppDemo/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/WpfAppDemo/DemoAppInfo.cs b/WpfAppDemo/DemoAppInfo.cs new file mode 100644 index 0000000..a167407 --- /dev/null +++ b/WpfAppDemo/DemoAppInfo.cs @@ -0,0 +1,37 @@ +using CommunityToolkit.Mvvm.Input; +using Leosac.WpfApp; +using Leosac.WpfApp.Domain; +using WpfAppDemo.Domain; + +namespace WpfAppDemo +{ + public class DemoAppInfo : LeosacWinAppInfo + { + public DemoAppInfo() + { + ApplicationName = "Demo App"; + ApplicationTitle = "Leosac Wpf Demo App"; + } + + public override void InitializeAboutWindow(AboutWindowViewModel model) + { + + } + + public override void InitializeMainWindow(MainWindowViewModel model) + { + var HomeCommand = new RelayCommand( + () => + { + model.SelectedIndex = 0; + }); + + model.MenuItems.Add(new NavItem( + "Home", + typeof(HomeControl), + "House", + new HomeControlViewModel(model.SnackbarMessageQueue) + )); + } + } +} diff --git a/WpfAppDemo/Domain/HomeControlViewModel.cs b/WpfAppDemo/Domain/HomeControlViewModel.cs new file mode 100644 index 0000000..5e907ba --- /dev/null +++ b/WpfAppDemo/Domain/HomeControlViewModel.cs @@ -0,0 +1,31 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using Leosac.WpfApp; +using MaterialDesignThemes.Wpf; + +namespace WpfAppDemo.Domain +{ + public class HomeControlViewModel : ObservableValidator + { + private readonly ISnackbarMessageQueue _snackbarMessageQueue; + + public HomeControlViewModel(ISnackbarMessageQueue snackbarMessageQueue) + { + _snackbarMessageQueue = snackbarMessageQueue; + + SnackbarInfoCommand = new RelayCommand(() => + { + SnackbarHelper.EnqueueMessage(_snackbarMessageQueue, "Simple information message."); + }); + + SnackbarErrorCommand = new RelayCommand(() => + { + SnackbarHelper.EnqueueError(_snackbarMessageQueue, "An error message. This message is usually longer than other messages as some details may be included."); + }); + } + + public RelayCommand SnackbarInfoCommand { get; } + + public RelayCommand SnackbarErrorCommand { get; } + } +} diff --git a/WpfAppDemo/HomeControl.xaml b/WpfAppDemo/HomeControl.xaml new file mode 100644 index 0000000..161cdc0 --- /dev/null +++ b/WpfAppDemo/HomeControl.xaml @@ -0,0 +1,15 @@ + + +