Skip to content

Commit a2c1071

Browse files
committed
hashing around snackbar API ideas
1 parent d57b03a commit a2c1071

File tree

1 file changed

+112
-1
lines changed

1 file changed

+112
-1
lines changed

MaterialDesignThemes.Wpf/Snackbar.cs

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5+
using System.Threading;
56
using System.Threading.Tasks;
67
using System.Windows;
78
using System.Windows.Controls;
@@ -11,6 +12,116 @@
1112

1213
namespace MaterialDesignThemes.Wpf
1314
{
15+
16+
/*
17+
Potential usage:
18+
19+
<Snackbar MessageQueue="{Binding MessageQueue}" />
20+
21+
//would work in both MVVM and code behind.
22+
23+
//with interface could be injected down in MVVM
24+
25+
//create default value for code behind
26+
27+
THOUGHTS
28+
* stop consecutive identical content (within a time span)
29+
* what if multiple snackbars are bound to the same queue (stop multiple assocations?)
30+
* us e a controller like dragablz...this would allow plugable control:
31+
32+
<Snackbar>
33+
<Snackbar.Controller>
34+
<SnackbarController MessageQueue={Binding MessageQueue} />
35+
</Snakbar.Controller>
36+
</Snackbar>
37+
38+
...having the controller allows us to pull a lot of interaction off the control itself...but a bit more verbose XAML
39+
40+
..maybe the message queue is the controller...i dunno right now...
41+
42+
43+
** Just THRASHING OUT IDEAS HERE....**
44+
45+
Multiple windows...having the option for one shared queue is nice...if a notification comes in, we can route to the foreground window...
46+
47+
48+
49+
<Snackbar MessageQueue="{Binding MessageQueue}" />
50+
51+
*/
52+
53+
public interface ISnackbarMessageQueue
54+
{
55+
void Post(object content);
56+
57+
void Post(object content, object actionContent, Action actionHandler);
58+
59+
void Post<TArgument>(object content, object actionContent, Action<TArgument> actionHandler, TArgument actionArgument);
60+
}
61+
62+
internal class SnackbarMessageQueueRegistration
63+
{
64+
public SnackbarMessageQueueRegistration(Snackbar2 snackbar2)
65+
{
66+
Snackbar2 = snackbar2;
67+
}
68+
69+
public Snackbar2 Snackbar2 { get; }
70+
}
71+
72+
public class SnackbarMessageQueue : ISnackbarMessageQueue
73+
{
74+
private readonly IList<SnackbarMessageQueueRegistration> _pairedSnackbars = new List<SnackbarMessageQueueRegistration>();
75+
76+
//oh if only I had Disposable.Create in this lib :) tempted to copy it in like dragabalz,
77+
//but this is an internal method so no one will know my direty Action disposer...
78+
internal Action Pair(Snackbar2 snackbar)
79+
{
80+
//assume this internal method is on Dispatcher
81+
82+
if (snackbar == null) throw new ArgumentNullException(nameof(snackbar));
83+
84+
// if (_pairedSnackbars)
85+
// _pairedSnackbars.Add(snackbar);
86+
87+
// return () => _pairedSnackbars.Remove(snackbar);
88+
return null;
89+
90+
//TODO worry about loading unloading...could cause a little leaky if u not carefull...
91+
}
92+
93+
public void Post(object content)
94+
{
95+
throw new NotImplementedException();
96+
}
97+
98+
public void Post(object content, object actionContent, Action actionHandler)
99+
{
100+
throw new NotImplementedException();
101+
}
102+
103+
public void Post<TArgument>(object content, object actionContent, Action<TArgument> actionHandler, TArgument actionArgument)
104+
{
105+
throw new NotImplementedException();
106+
}
107+
}
108+
109+
110+
111+
112+
113+
114+
/// <summary>
115+
/// Implements a <see cref="Snackbar"/> inspired by the Material Design specs (https://material.google.com/components/snackbars-toasts.html).
116+
/// </summary>
117+
public class Snackbar2 : Control
118+
{
119+
static Snackbar2()
120+
{
121+
DefaultStyleKeyProperty.OverrideMetadata(typeof(Snackbar2), new FrameworkPropertyMetadata(typeof(Snackbar2)));
122+
}
123+
}
124+
14125
/// <summary>
15126
/// Implements a <see cref="Snackbar"/> inspired by the Material Design specs (https://material.google.com/components/snackbars-toasts.html).
16127
/// </summary>
@@ -100,7 +211,7 @@ public object ActionLabel
100211
{
101212
SetValue(ActionLabelProperty, value);
102213
}
103-
}
214+
}
104215

105216
private static async void ContentChangedHandler(DependencyObject sender, DependencyPropertyChangedEventArgs args)
106217
{

0 commit comments

Comments
 (0)