|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Linq;
|
4 | 4 | using System.Text;
|
| 5 | +using System.Threading; |
5 | 6 | using System.Threading.Tasks;
|
6 | 7 | using System.Windows;
|
7 | 8 | using System.Windows.Controls;
|
|
11 | 12 |
|
12 | 13 | namespace MaterialDesignThemes.Wpf
|
13 | 14 | {
|
| 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 | + |
14 | 125 | /// <summary>
|
15 | 126 | /// Implements a <see cref="Snackbar"/> inspired by the Material Design specs (https://material.google.com/components/snackbars-toasts.html).
|
16 | 127 | /// </summary>
|
@@ -100,7 +211,7 @@ public object ActionLabel
|
100 | 211 | {
|
101 | 212 | SetValue(ActionLabelProperty, value);
|
102 | 213 | }
|
103 |
| - } |
| 214 | + } |
104 | 215 |
|
105 | 216 | private static async void ContentChangedHandler(DependencyObject sender, DependencyPropertyChangedEventArgs args)
|
106 | 217 | {
|
|
0 commit comments