From 4cb79d2945f587ff651fbf31832f11007e6cf002 Mon Sep 17 00:00:00 2001
From: Ivan Dmitriev <42055372+IvanDmitriev1@users.noreply.github.com>
Date: Thu, 27 Apr 2023 12:36:47 +0600
Subject: [PATCH 1/9] Added SnackbarControl folder
---
src/Wpf.Ui/Common/RoutedSnackbarEvent.cs | 14 ++++++++---
src/Wpf.Ui/Contracts/ISnackbarService.cs | 1 +
.../{ => SnackbarControl}/ISnackbarControl.cs | 2 +-
.../{ => SnackbarControl}/Snackbar.bmp | Bin
.../{ => SnackbarControl}/Snackbar.cs | 22 +++++++++---------
src/Wpf.Ui/Properties/AssemblyInfo.cs | 1 +
src/Wpf.Ui/Services/SnackbarService.cs | 1 +
src/Wpf.Ui/Styles/Controls/Snackbar.xaml | 7 +++---
src/Wpf.Ui/Wpf.Ui.csproj | 2 +-
9 files changed, 31 insertions(+), 19 deletions(-)
rename src/Wpf.Ui/Controls/{ => SnackbarControl}/ISnackbarControl.cs (99%)
rename src/Wpf.Ui/Controls/{ => SnackbarControl}/Snackbar.bmp (100%)
rename src/Wpf.Ui/Controls/{ => SnackbarControl}/Snackbar.cs (93%)
diff --git a/src/Wpf.Ui/Common/RoutedSnackbarEvent.cs b/src/Wpf.Ui/Common/RoutedSnackbarEvent.cs
index ee24a8195..6bef96d7d 100644
--- a/src/Wpf.Ui/Common/RoutedSnackbarEvent.cs
+++ b/src/Wpf.Ui/Common/RoutedSnackbarEvent.cs
@@ -5,15 +5,23 @@
using System.Diagnostics.CodeAnalysis;
using System.Windows;
+using Wpf.Ui.Controls.SnackbarControl;
namespace Wpf.Ui.Common;
///
-/// Event triggered on via .
+/// Event triggered on via .
///
-/// Current instance.
+/// Current instance.
#if NET5_0_OR_GREATER
+
+/* Unmerged change from project 'Wpf.Ui (net6.0-windows)'
+Before:
public delegate void RoutedSnackbarEvent([NotNull] Controls.Snackbar sender, RoutedEventArgs e);
+After:
+public delegate void RoutedSnackbarEvent([NotNull] Controls.SnackbarControl.Snackbar sender, RoutedEventArgs e);
+*/
+public delegate void RoutedSnackbarEvent([NotNull] Snackbar sender, RoutedEventArgs e);
#else
-public delegate void RoutedSnackbarEvent(Controls.Snackbar sender, RoutedEventArgs e);
+public delegate void RoutedSnackbarEvent(Controls.SnackbarControl.Snackbar sender, RoutedEventArgs e);
#endif
diff --git a/src/Wpf.Ui/Contracts/ISnackbarService.cs b/src/Wpf.Ui/Contracts/ISnackbarService.cs
index d66ee9196..dd303cec0 100644
--- a/src/Wpf.Ui/Contracts/ISnackbarService.cs
+++ b/src/Wpf.Ui/Contracts/ISnackbarService.cs
@@ -7,6 +7,7 @@
using Wpf.Ui.Common;
using Wpf.Ui.Controls;
using Wpf.Ui.Controls.IconElements;
+using Wpf.Ui.Controls.SnackbarControl;
namespace Wpf.Ui.Contracts;
diff --git a/src/Wpf.Ui/Controls/ISnackbarControl.cs b/src/Wpf.Ui/Controls/SnackbarControl/ISnackbarControl.cs
similarity index 99%
rename from src/Wpf.Ui/Controls/ISnackbarControl.cs
rename to src/Wpf.Ui/Controls/SnackbarControl/ISnackbarControl.cs
index 97f0daa68..54a5db6da 100644
--- a/src/Wpf.Ui/Controls/ISnackbarControl.cs
+++ b/src/Wpf.Ui/Controls/SnackbarControl/ISnackbarControl.cs
@@ -7,7 +7,7 @@
using Wpf.Ui.Common;
using Wpf.Ui.Controls.IconElements;
-namespace Wpf.Ui.Controls;
+namespace Wpf.Ui.Controls.SnackbarControl;
///
/// Snackbar inform user of a process that an app has performed or will perform. It appears temporarily, towards the bottom of the window.
diff --git a/src/Wpf.Ui/Controls/Snackbar.bmp b/src/Wpf.Ui/Controls/SnackbarControl/Snackbar.bmp
similarity index 100%
rename from src/Wpf.Ui/Controls/Snackbar.bmp
rename to src/Wpf.Ui/Controls/SnackbarControl/Snackbar.bmp
diff --git a/src/Wpf.Ui/Controls/Snackbar.cs b/src/Wpf.Ui/Controls/SnackbarControl/Snackbar.cs
similarity index 93%
rename from src/Wpf.Ui/Controls/Snackbar.cs
rename to src/Wpf.Ui/Controls/SnackbarControl/Snackbar.cs
index 105b65849..7895f1ea5 100644
--- a/src/Wpf.Ui/Controls/Snackbar.cs
+++ b/src/Wpf.Ui/Controls/SnackbarControl/Snackbar.cs
@@ -15,7 +15,7 @@
using Brush = System.Windows.Media.Brush;
using SystemColors = System.Windows.SystemColors;
-namespace Wpf.Ui.Controls;
+namespace Wpf.Ui.Controls.SnackbarControl;
///
/// Snackbar inform user of a process that an app has performed or will perform. It appears temporarily, towards the bottom of the window.
@@ -69,8 +69,8 @@ public class Snackbar : System.Windows.Controls.ContentControl, ISnackbarControl
/// Property for .
///
public static readonly DependencyProperty AppearanceProperty = DependencyProperty.Register(nameof(Appearance),
- typeof(Controls.ControlAppearance), typeof(Snackbar),
- new PropertyMetadata(Controls.ControlAppearance.Secondary));
+ typeof(ControlAppearance), typeof(Snackbar),
+ new PropertyMetadata(ControlAppearance.Secondary));
///
/// Property for .
@@ -91,7 +91,7 @@ public class Snackbar : System.Windows.Controls.ContentControl, ISnackbarControl
///
public static readonly DependencyProperty TemplateButtonCommandProperty =
DependencyProperty.Register(nameof(TemplateButtonCommand),
- typeof(Common.IRelayCommand), typeof(Snackbar), new PropertyMetadata(null));
+ typeof(IRelayCommand), typeof(Snackbar), new PropertyMetadata(null));
///
public bool IsShown
@@ -143,9 +143,9 @@ public Brush MessageForeground
///
[Bindable(true), Category("Appearance")]
- public Controls.ControlAppearance Appearance
+ public ControlAppearance Appearance
{
- get => (Controls.ControlAppearance)GetValue(AppearanceProperty);
+ get => (ControlAppearance)GetValue(AppearanceProperty);
set => SetValue(AppearanceProperty, value);
}
@@ -192,9 +192,9 @@ public event RoutedSnackbarEvent Closed
}
///
- /// Gets the triggered after clicking close button.
+ /// Gets the triggered after clicking close button.
///
- public Common.IRelayCommand TemplateButtonCommand => (Common.IRelayCommand)GetValue(TemplateButtonCommandProperty);
+ public IRelayCommand TemplateButtonCommand => (IRelayCommand)GetValue(TemplateButtonCommandProperty);
///
@@ -202,7 +202,7 @@ public Snackbar()
{
_eventIdentifier = new EventIdentifier();
- SetValue(TemplateButtonCommandProperty, new Common.RelayCommand(OnTemplateButtonClick));
+ SetValue(TemplateButtonCommandProperty, new RelayCommand(OnTemplateButtonClick));
}
///
@@ -305,7 +305,7 @@ protected virtual async void OnTemplateButtonClick(string? parameter)
protected virtual void OnOpened()
{
RaiseEvent(new RoutedEventArgs(
- Snackbar.OpenedEvent,
+ OpenedEvent,
this));
}
@@ -315,7 +315,7 @@ protected virtual void OnOpened()
protected virtual void OnClosed()
{
RaiseEvent(new RoutedEventArgs(
- Snackbar.ClosedEvent,
+ ClosedEvent,
this));
}
diff --git a/src/Wpf.Ui/Properties/AssemblyInfo.cs b/src/Wpf.Ui/Properties/AssemblyInfo.cs
index 43d75de93..8593af270 100644
--- a/src/Wpf.Ui/Properties/AssemblyInfo.cs
+++ b/src/Wpf.Ui/Properties/AssemblyInfo.cs
@@ -30,3 +30,4 @@
[assembly: XmlnsDefinition("http://schemas.lepo.co/wpfui/2022/xaml", "Wpf.Ui.Controls.BreadcrumbControl")]
[assembly: XmlnsDefinition("http://schemas.lepo.co/wpfui/2022/xaml", "Wpf.Ui.Controls.IconElements")]
[assembly: XmlnsDefinition("http://schemas.lepo.co/wpfui/2022/xaml", "Wpf.Ui.Controls.IconSources")]
+[assembly: XmlnsDefinition("http://schemas.lepo.co/wpfui/2022/xaml", "Wpf.Ui.Controls.SnackbarControl")]
diff --git a/src/Wpf.Ui/Services/SnackbarService.cs b/src/Wpf.Ui/Services/SnackbarService.cs
index d3246313d..9d316072c 100644
--- a/src/Wpf.Ui/Services/SnackbarService.cs
+++ b/src/Wpf.Ui/Services/SnackbarService.cs
@@ -11,6 +11,7 @@
using Wpf.Ui.Contracts;
using Wpf.Ui.Controls;
using Wpf.Ui.Controls.IconElements;
+using Wpf.Ui.Controls.SnackbarControl;
namespace Wpf.Ui.Services;
diff --git a/src/Wpf.Ui/Styles/Controls/Snackbar.xaml b/src/Wpf.Ui/Styles/Controls/Snackbar.xaml
index fdf8805d4..1ee7b04b4 100644
--- a/src/Wpf.Ui/Styles/Controls/Snackbar.xaml
+++ b/src/Wpf.Ui/Styles/Controls/Snackbar.xaml
@@ -9,9 +9,10 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Wpf.Ui.Controls"
- xmlns:iconElements="clr-namespace:Wpf.Ui.Controls.IconElements">
+ xmlns:iconElements="clr-namespace:Wpf.Ui.Controls.IconElements"
+ xmlns:snackbarControl="clr-namespace:Wpf.Ui.Controls.SnackbarControl">
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
From 8031a8ad8dc9a95c8e8ba934736588f4d865005a Mon Sep 17 00:00:00 2001
From: Ivan Dmitriev <42055372+IvanDmitriev1@users.noreply.github.com>
Date: Thu, 27 Apr 2023 16:21:30 +0600
Subject: [PATCH 3/9] Added ContentForeground
---
.../Pages/DialogsAndFlyouts/SnackbarPage.xaml | 2 +-
.../Controls/SnackbarControl/NewSnackbar.cs | 21 +++++++++-
.../SnackbarControl/SnackbarPresenter.cs | 22 +++++-----
src/Wpf.Ui/Styles/Controls/Snackbar.xaml | 41 +++++++++++--------
4 files changed, 56 insertions(+), 30 deletions(-)
diff --git a/src/Wpf.Ui.Gallery/Views/Pages/DialogsAndFlyouts/SnackbarPage.xaml b/src/Wpf.Ui.Gallery/Views/Pages/DialogsAndFlyouts/SnackbarPage.xaml
index 874989524..b76cae249 100644
--- a/src/Wpf.Ui.Gallery/Views/Pages/DialogsAndFlyouts/SnackbarPage.xaml
+++ b/src/Wpf.Ui.Gallery/Views/Pages/DialogsAndFlyouts/SnackbarPage.xaml
@@ -87,7 +87,7 @@
IsSnapToTickEnabled="True"
Maximum="5"
Minimum="1"
- TickFrequency="200"
+ TickFrequency="1"
TickPlacement="BottomRight"
Value="{Binding ViewModel.SnackbarTimeout, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:SnackbarPage}, Mode=TwoWay}" />
diff --git a/src/Wpf.Ui/Controls/SnackbarControl/NewSnackbar.cs b/src/Wpf.Ui/Controls/SnackbarControl/NewSnackbar.cs
index bb1c3e68f..dbece980a 100644
--- a/src/Wpf.Ui/Controls/SnackbarControl/NewSnackbar.cs
+++ b/src/Wpf.Ui/Controls/SnackbarControl/NewSnackbar.cs
@@ -6,6 +6,7 @@
using System;
using System.ComponentModel;
using System.Windows;
+using System.Windows.Controls;
using System.Windows.Media;
using Wpf.Ui.Common;
using Wpf.Ui.Controls.IconElements;
@@ -13,7 +14,7 @@
namespace Wpf.Ui.Controls.SnackbarControl;
-public class NewSnackbar : System.Windows.Controls.ContentControl
+public class NewSnackbar : ContentControl
{
#region Static properties
@@ -76,6 +77,14 @@ public class NewSnackbar : System.Windows.Controls.ContentControl
DependencyProperty.Register(nameof(TemplateButtonCommand),
typeof(IRelayCommand), typeof(NewSnackbar), new PropertyMetadata(null));
+ ///
+ /// Property for .
+ ///
+ public static readonly DependencyProperty ContentForegroundProperty = DependencyProperty.Register(
+ nameof(ContentForeground),
+ typeof(Brush), typeof(NewSnackbar), new FrameworkPropertyMetadata(SystemColors.ControlTextBrush,
+ FrameworkPropertyMetadataOptions.Inherits));
+
#endregion
#region Properties
@@ -154,6 +163,16 @@ public ControlAppearance Appearance
set => SetValue(AppearanceProperty, value);
}
+ ///
+ /// Foreground of the .
+ ///
+ [Bindable(true), Category("Appearance")]
+ public Brush ContentForeground
+ {
+ get => (Brush)GetValue(ContentForegroundProperty);
+ set => SetValue(ContentForegroundProperty, value);
+ }
+
///
/// Command triggered after clicking the button in the template.
///
diff --git a/src/Wpf.Ui/Controls/SnackbarControl/SnackbarPresenter.cs b/src/Wpf.Ui/Controls/SnackbarControl/SnackbarPresenter.cs
index e78a5b9a8..0733d88eb 100644
--- a/src/Wpf.Ui/Controls/SnackbarControl/SnackbarPresenter.cs
+++ b/src/Wpf.Ui/Controls/SnackbarControl/SnackbarPresenter.cs
@@ -26,24 +26,24 @@ public SnackbarPresenter()
};
}
- protected readonly Queue _queue = new();
- protected CancellationTokenSource _cancellationTokenSource = new();
+ protected readonly Queue Queue = new();
+ protected CancellationTokenSource CancellationTokenSource = new();
protected virtual void OnUnloaded()
{
- _cancellationTokenSource.Cancel();
- _cancellationTokenSource.Dispose();
+ CancellationTokenSource.Cancel();
+ CancellationTokenSource.Dispose();
}
protected void ResetCancellationTokenSource()
{
- _cancellationTokenSource.Dispose();
- _cancellationTokenSource = new CancellationTokenSource();
+ CancellationTokenSource.Dispose();
+ CancellationTokenSource = new CancellationTokenSource();
}
public virtual void AddToQue(NewSnackbar newSnackbar)
{
- _queue.Enqueue(newSnackbar);
+ Queue.Enqueue(newSnackbar);
if (Content is null)
ShowQueuedSnackbars();
@@ -62,16 +62,16 @@ public virtual async Task HideCurrent()
if (Content is null)
return;
- _cancellationTokenSource.Cancel();
+ CancellationTokenSource.Cancel();
await HidSnackbar(Content);
ResetCancellationTokenSource();
}
private async void ShowQueuedSnackbars()
{
- while (_queue.Count > 0 && !_cancellationTokenSource.IsCancellationRequested)
+ while (Queue.Count > 0 && !CancellationTokenSource.IsCancellationRequested)
{
- var snackbar = _queue.Dequeue();
+ var snackbar = Queue.Dequeue();
await ShowSnackbar(snackbar);
}
}
@@ -83,7 +83,7 @@ private async Task ShowSnackbar(NewSnackbar snackbar)
try
{
- await Task.Delay(snackbar.Timeout, _cancellationTokenSource.Token);
+ await Task.Delay(snackbar.Timeout, CancellationTokenSource.Token);
}
catch
{
diff --git a/src/Wpf.Ui/Styles/Controls/Snackbar.xaml b/src/Wpf.Ui/Styles/Controls/Snackbar.xaml
index bf910575d..4e75eefe2 100644
--- a/src/Wpf.Ui/Styles/Controls/Snackbar.xaml
+++ b/src/Wpf.Ui/Styles/Controls/Snackbar.xaml
@@ -304,6 +304,11 @@
+
+
+
+
+
@@ -369,11 +374,12 @@
+ TextElement.FontWeight="SemiBold"
+ TextElement.Foreground="{TemplateBinding Foreground}" />
+ TextElement.FontWeight="Regular"
+ TextElement.Foreground="{TemplateBinding ContentForeground}">
-
-
-
-
+
+
Date: Thu, 27 Apr 2023 20:38:58 +0600
Subject: [PATCH 9/9] Changed show method parameters
---
.../ViewModels/Pages/DialogsAndFlyouts/SnackbarViewModel.cs | 4 ++--
src/Wpf.Ui/Contracts/ISnackbarService.cs | 4 ++--
src/Wpf.Ui/Services/SnackbarService.cs | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/Wpf.Ui.Gallery/ViewModels/Pages/DialogsAndFlyouts/SnackbarViewModel.cs b/src/Wpf.Ui.Gallery/ViewModels/Pages/DialogsAndFlyouts/SnackbarViewModel.cs
index 7bbd8ae93..aa76e0571 100644
--- a/src/Wpf.Ui.Gallery/ViewModels/Pages/DialogsAndFlyouts/SnackbarViewModel.cs
+++ b/src/Wpf.Ui.Gallery/ViewModels/Pages/DialogsAndFlyouts/SnackbarViewModel.cs
@@ -36,8 +36,8 @@ public int SnackbarAppearanceComboBoxSelectedIndex
[RelayCommand]
private void OnOpenSnackbar(object sender)
{
- _snackbarService.Show("Don't Blame Yourself.", "No Witcher's Ever Died In His Bed.",
- TimeSpan.FromSeconds(SnackbarTimeout), _snackbarAppearance, new SymbolIcon(SymbolRegular.Fluent24));
+ _snackbarService.Show("Don't Blame Yourself.", "No Witcher's Ever Died In His Bed.", _snackbarAppearance,
+ new SymbolIcon(SymbolRegular.Fluent24), TimeSpan.FromSeconds(SnackbarTimeout));
}
private void UpdateSnackbarAppearance(int appearanceIndex)
diff --git a/src/Wpf.Ui/Contracts/ISnackbarService.cs b/src/Wpf.Ui/Contracts/ISnackbarService.cs
index df5e02cfc..785832ecd 100644
--- a/src/Wpf.Ui/Contracts/ISnackbarService.cs
+++ b/src/Wpf.Ui/Contracts/ISnackbarService.cs
@@ -38,8 +38,8 @@ public interface ISnackbarService
///
///
///
- ///
///
///
- void Show(string title, string message, TimeSpan timeout = default, ControlAppearance appearance = ControlAppearance.Secondary, IconElement? icon = null);
+ ///
+ void Show(string title, string message, ControlAppearance appearance = ControlAppearance.Secondary, IconElement? icon = null, TimeSpan timeout = default);
}
diff --git a/src/Wpf.Ui/Services/SnackbarService.cs b/src/Wpf.Ui/Services/SnackbarService.cs
index de5bd602a..aca3a32c3 100644
--- a/src/Wpf.Ui/Services/SnackbarService.cs
+++ b/src/Wpf.Ui/Services/SnackbarService.cs
@@ -38,7 +38,7 @@ public SnackbarPresenter GetSnackbarPresenter()
}
///
- public void Show(string title, string message, TimeSpan timeout = default, ControlAppearance appearance = ControlAppearance.Secondary, IconElement? icon = null)
+ public void Show(string title, string message, ControlAppearance appearance = ControlAppearance.Secondary, IconElement? icon = null, TimeSpan timeout = default)
{
if (_presenter is null)
throw new ArgumentNullException($"The SnackbarPresenter didn't set previously.");