Skip to content

Commit d70a575

Browse files
committed
fleshing out snackbar message queue - API coming along...got to manage edge cases around mouse overs and dialogs
1 parent 860170e commit d70a575

14 files changed

+577
-157
lines changed

MainDemo.Wpf/App.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Application x:Class="MaterialDesignColors.WpfExample.App"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
StartupUri="MainWindow.xaml">
4+
StartupUri="ProvingGround.xaml">
55
<Application.Resources>
66
<ResourceDictionary>
77
<ResourceDictionary.MergedDictionaries>

MainDemo.Wpf/ProvingGround.xaml

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,46 @@
3333
</UserControl.Resources>
3434

3535
<Grid HorizontalAlignment="Left">
36-
<StackPanel>
37-
<provingGroundStuff:MeasuringTextBox>Hello World</provingGroundStuff:MeasuringTextBox>
38-
<provingGroundStuff:MeasuringTextBox>Hello World</provingGroundStuff:MeasuringTextBox>
39-
<provingGroundStuff:MeasuringTextBox>Hello World</provingGroundStuff:MeasuringTextBox>
40-
<provingGroundStuff:MeasuringTextBox>Hello World</provingGroundStuff:MeasuringTextBox>
41-
<provingGroundStuff:MeasuringTextBox>Hello World</provingGroundStuff:MeasuringTextBox>
42-
<provingGroundStuff:MeasuringTextBox materialDesign:HintAssist.Hint="Float">Hello World</provingGroundStuff:MeasuringTextBox>
43-
<provingGroundStuff:MeasuringTextBox materialDesign:HintAssist.IsFloating="True" materialDesign:HintAssist.Hint="Float">Hello World</provingGroundStuff:MeasuringTextBox>
36+
<Grid.RowDefinitions>
37+
<RowDefinition />
38+
<RowDefinition />
39+
</Grid.RowDefinitions>
40+
<Grid.ColumnDefinitions>
41+
<ColumnDefinition />
42+
<ColumnDefinition />
43+
<ColumnDefinition />
44+
</Grid.ColumnDefinitions>
45+
46+
<materialDesign:Snackbar2 Message="hello 1"
47+
IsActive="False"
48+
x:Name="SnackbarOne" />
49+
50+
<ToggleButton IsChecked="{Binding ElementName=SnackbarOne, Path=IsActive, Mode=TwoWay}"
51+
Grid.Row="1" Grid.Column="0" />
52+
53+
<materialDesign:Snackbar2 IsActive="True"
54+
Grid.Row="0"
55+
Grid.Column="1"
56+
x:Name="SnackbarTwo" >
57+
<materialDesign:SnackbarMessage Content="Hello 2" ActionContent="UNDO" />
58+
</materialDesign:Snackbar2>
59+
60+
<ToggleButton IsChecked="{Binding ElementName=SnackbarTwo, Path=IsActive, Mode=TwoWay}"
61+
Grid.Row="1" Grid.Column="1" />
62+
63+
64+
<materialDesign:Snackbar2 MessageQueue="{materialDesign:MessageQueue}"
65+
Grid.Row="0"
66+
Grid.Column="2"
67+
x:Name="SnackbarThree" />
68+
<StackPanel Orientation="Horizontal"
69+
Grid.Row="1"
70+
Grid.Column="2" >
71+
<TextBlock>Message: </TextBlock>
72+
<TextBlock x:Name="MessageTextBox">Hello World</TextBlock>
73+
<Button Click="SnackBar3_OnClick">Send</Button>
4474
</StackPanel>
75+
4576
</Grid>
4677

4778
</UserControl>

MainDemo.Wpf/ProvingGround.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
5454
{
5555
new PaletteHelper().QueryPalette();
5656
}
57+
58+
private void SnackBar3_OnClick(object sender, RoutedEventArgs e)
59+
{
60+
SnackbarThree.MessageQueue.Enqueue(MessageTextBox.Text);
61+
}
5762
}
5863

5964
public class ProvingGroundViewModel : INotifyPropertyChanged
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Globalization;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace MaterialDesignThemes.Wpf.Converters
10+
{
11+
public class SnackbarMessageTypeConverter : TypeConverter
12+
{
13+
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
14+
{
15+
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
16+
}
17+
18+
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
19+
{
20+
var s = value as string;
21+
if (s != null)
22+
{
23+
return new SnackbarMessage
24+
{
25+
Content = s
26+
};
27+
}
28+
29+
return base.ConvertFrom(context, culture, value);
30+
}
31+
}
32+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
3+
namespace MaterialDesignThemes.Wpf
4+
{
5+
public interface ISnackbarMessageQueue
6+
{
7+
void Enqueue(object content);
8+
9+
void Enqueue(object content, object actionContent, Action actionHandler);
10+
11+
void Enqueue<TArgument>(object content, object actionContent, Action<TArgument> actionHandler, TArgument actionArgument);
12+
13+
//TODO consider additional variants of Enqueue:
14+
// ShowAsync(. . .)
15+
}
16+
}

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@
271271
<Compile Include="Converters\PointValueConverter.cs" />
272272
<Compile Include="Converters\ShadowConverter.cs" />
273273
<Compile Include="Converters\SizeToRectConverter.cs" />
274+
<Compile Include="Converters\SnackbarMessageTypeConverter.cs" />
274275
<Compile Include="Converters\TimeToVisibilityConverter.cs" />
275276
<Compile Include="CustomPopupPlacementCallbackHelper.cs" />
276277
<Compile Include="DataGridAssist.cs" />
@@ -292,9 +293,14 @@
292293
<Compile Include="HintProxyFabric.cs" />
293294
<Compile Include="Icon.cs" />
294295
<Compile Include="IconType.cs" />
296+
<Compile Include="ISnackbarMessageQueue.cs" />
295297
<Compile Include="ListBoxAssist.cs" />
298+
<Compile Include="MessageQueueExtension.cs" />
296299
<Compile Include="Palette.cs" />
297300
<Compile Include="Snackbar.cs" />
301+
<Compile Include="SnackbarMessageEventArgs.cs" />
302+
<Compile Include="SnackbarMessageQueue.cs" />
303+
<Compile Include="SnackbarMessageQueueItem.cs" />
298304
<Compile Include="Transitions\CircleWipe.cs" />
299305
<Compile Include="IHintProxy.cs" />
300306
<Compile Include="Transitions\IndexedItemOffsetMultiplierExtension.cs" />
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Windows.Markup;
3+
4+
namespace MaterialDesignThemes.Wpf
5+
{
6+
/// <summary>
7+
/// Provides shorthand to initialise a new <see cref="SnackbarMessageQueue"/> for a <see cref="Snackbar2"/>.
8+
/// </summary>
9+
[MarkupExtensionReturnType(typeof(SnackbarMessageQueue))]
10+
public class MessageQueueExtension : MarkupExtension
11+
{
12+
public override object ProvideValue(IServiceProvider serviceProvider)
13+
{
14+
return new SnackbarMessageQueue();
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)