Skip to content

Commit 41a56c5

Browse files
committed
make icon pack snackbar message a bit more mvvm
1 parent e31b47b commit 41a56c5

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

MainDemo.Wpf/Domain/MainWindowViewModel.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
using MaterialDesignThemes.Wpf;
55
using MaterialDesignThemes.Wpf.Transitions;
66
using System.Windows.Controls;
7+
using System;
78

89
namespace MaterialDesignColors.WpfExample.Domain
910
{
1011
public class MainWindowViewModel
1112
{
12-
public MainWindowViewModel()
13+
public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue)
1314
{
15+
if (snackbarMessageQueue == null) throw new ArgumentNullException(nameof(snackbarMessageQueue));
16+
1417
DemoItems = new[]
1518
{
1619
new DemoItem("Home", new Home(),
@@ -92,7 +95,7 @@ public MainWindowViewModel()
9295
{
9396
VerticalScrollBarVisibilityRequirement = ScrollBarVisibility.Auto
9497
},
95-
new DemoItem("Icon Pack", new IconPack { DataContext = new IconPackViewModel() },
98+
new DemoItem("Icon Pack", new IconPack { DataContext = new IconPackViewModel(snackbarMessageQueue) },
9699
new []
97100
{
98101
DocumentationLink.DemoPageLink<IconPack>("Demo View"),

MainDemo.Wpf/IconPack.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<Button Margin="8 0" Command="{Binding CopyToClipboardCommand, Mode=OneTime}" CommandParameter="{Binding ElementName=KindsListBox, Path=SelectedValue}">
8585
<StackPanel Orientation="Horizontal">
8686
<materialDesign:PackIcon Kind="ContentCopy"/>
87-
<TextBlock Text="Copy To Clipboard"/>
87+
<TextBlock Text="Copy To Clipboard" Margin="8 0 0 0" />
8888
</StackPanel>
8989
</Button>
9090
</StackPanel>

MainDemo.Wpf/IconPackViewModel.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@ namespace MaterialDesignDemo
1717
public class IconPackViewModel : INotifyPropertyChanged
1818
{
1919
private readonly Lazy<IEnumerable<PackIconKind>> _packIconKinds;
20+
private readonly ISnackbarMessageQueue _snackbarMessageQueue;
2021

21-
public IconPackViewModel()
22+
public IconPackViewModel(ISnackbarMessageQueue snackbarMessageQueue)
2223
{
24+
_snackbarMessageQueue = snackbarMessageQueue ?? throw new ArgumentNullException(nameof(snackbarMessageQueue));
25+
2326
OpenDotComCommand = new AnotherCommandImplementation(OpenDotCom);
2427
SearchCommand = new AnotherCommandImplementation(Search);
2528
CopyToClipboardCommand = new AnotherCommandImplementation(CopyToClipboard);
2629
_packIconKinds = new Lazy<IEnumerable<PackIconKind>>(() =>
2730
Enum.GetValues(typeof (PackIconKind)).OfType<PackIconKind>()
2831
.OrderBy(k => k.ToString(), StringComparer.InvariantCultureIgnoreCase).ToList()
2932
);
30-
3133
}
3234

3335
public ICommand OpenDotComCommand { get; }
@@ -66,7 +68,7 @@ private void CopyToClipboard(object obj)
6668
var kind = (PackIconKind?)obj;
6769
string toBeCopied = $"<materialDesign:PackIcon Kind=\"{kind}\" />";
6870
Clipboard.SetDataObject(toBeCopied);
69-
MainWindow.Snackbar.MessageQueue.Enqueue(toBeCopied + " is copied to clipboard!");
71+
_snackbarMessageQueue.Enqueue(toBeCopied + " copied to clipboard");
7072
}
7173

7274
public event PropertyChangedEventHandler PropertyChanged;

MainDemo.Wpf/MainWindow.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ public partial class MainWindow : Window {
1717
public static Snackbar Snackbar;
1818
public MainWindow()
1919
{
20-
InitializeComponent();
21-
22-
DataContext = new MainWindowViewModel();
20+
InitializeComponent();
2321

2422
Task.Factory.StartNew(() =>
2523
{
@@ -31,6 +29,8 @@ public MainWindow()
3129
MainSnackbar.MessageQueue.Enqueue("Welcome to Material Design In XAML Tookit");
3230
}, TaskScheduler.FromCurrentSynchronizationContext());
3331

32+
DataContext = new MainWindowViewModel(MainSnackbar.MessageQueue);
33+
3434
Snackbar = this.MainSnackbar;
3535
}
3636

0 commit comments

Comments
 (0)