Skip to content

Commit 404496a

Browse files
committed
Merge branch 'Snackbar' of https://github.com/spiegelp/MaterialDesignInXamlToolkit into sp-snackbar
2 parents 89e682a + 69da8cb commit 404496a

9 files changed

+651
-7
lines changed

MainDemo.Wpf/MainWindow.xaml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
<materialDesign:DrawerHost.LeftDrawerContent>
4141
<DockPanel MinWidth="212">
4242
<ToggleButton Style="{StaticResource MaterialDesignHamburgerToggleButton}"
43-
DockPanel.Dock="Top"
44-
HorizontalAlignment="Right" Margin="16"
45-
IsChecked="{Binding ElementName=MenuToggleButton, Path=IsChecked, Mode=TwoWay}" />
43+
DockPanel.Dock="Top"
44+
HorizontalAlignment="Right" Margin="16"
45+
IsChecked="{Binding ElementName=MenuToggleButton, Path=IsChecked, Mode=TwoWay}" />
4646
<ListBox x:Name="DemoItemsListBox" Margin="0 16 0 16" SelectedIndex="0"
47-
PreviewMouseLeftButtonUp="UIElement_OnPreviewMouseLeftButtonUp">
47+
PreviewMouseLeftButtonUp="UIElement_OnPreviewMouseLeftButtonUp">
4848
<ListBox.ItemTemplate>
4949
<DataTemplate DataType="domain:DemoItem">
5050
<TextBlock Text="{Binding Name}" Margin="32 0 32 0" />
@@ -88,6 +88,11 @@
8888
<wpfExample:Sliders />
8989
</domain:DemoItem.Content>
9090
</domain:DemoItem>
91+
<domain:DemoItem Name="Snackbar">
92+
<domain:DemoItem.Content>
93+
<wpfExample:Snackbar />
94+
</domain:DemoItem.Content>
95+
</domain:DemoItem>
9196
<domain:DemoItem Name="Chips">
9297
<domain:DemoItem.Content>
9398
<wpfExample:Chips />
@@ -188,10 +193,10 @@
188193
</materialDesign:DrawerHost.LeftDrawerContent>
189194
<DockPanel>
190195
<materialDesign:ColorZone Padding="16" materialDesign:ShadowAssist.ShadowDepth="Depth2"
191-
Mode="PrimaryMid" DockPanel.Dock="Top">
196+
Mode="PrimaryMid" DockPanel.Dock="Top">
192197
<DockPanel>
193198
<ToggleButton Style="{StaticResource MaterialDesignHamburgerToggleButton}" IsChecked="False"
194-
x:Name="MenuToggleButton"/>
199+
x:Name="MenuToggleButton"/>
195200
<materialDesign:PopupBox DockPanel.Dock="Right" PlacementMode="BottomAndAlignRightEdges" StaysOpen="False">
196201
<StackPanel>
197202
<Button Content="Hello World" Click="MenuPopupButton_OnClick"/>
@@ -204,7 +209,7 @@
204209
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="22">Material Design In XAML Toolkit</TextBlock>
205210
</DockPanel>
206211
</materialDesign:ColorZone>
207-
<ContentControl Margin="16" Content="{Binding ElementName=DemoItemsListBox, Path=SelectedItem.Content}" />
212+
<ContentControl Margin="16" Content="{Binding ElementName=DemoItemsListBox, Path=SelectedItem.Content}" />
208213
</DockPanel>
209214
</materialDesign:DrawerHost>
210215
</materialDesign:DialogHost>

MainDemo.Wpf/MaterialDesignDemo.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@
153153
<Compile Include="Sliders.xaml.cs">
154154
<DependentUpon>Sliders.xaml</DependentUpon>
155155
</Compile>
156+
<Compile Include="Snackbar.xaml.cs">
157+
<DependentUpon>Snackbar.xaml</DependentUpon>
158+
</Compile>
156159
<Compile Include="TextFields.xaml.cs">
157160
<DependentUpon>TextFields.xaml</DependentUpon>
158161
</Compile>
@@ -297,6 +300,10 @@
297300
<SubType>Designer</SubType>
298301
<Generator>MSBuild:Compile</Generator>
299302
</Page>
303+
<Page Include="Snackbar.xaml">
304+
<SubType>Designer</SubType>
305+
<Generator>MSBuild:Compile</Generator>
306+
</Page>
300307
<Page Include="TextFields.xaml">
301308
<SubType>Designer</SubType>
302309
<Generator>MSBuild:Compile</Generator>

MainDemo.Wpf/Snackbar.xaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<UserControl x:Class="MaterialDesignColors.WpfExample.Snackbar"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:MaterialDesignDemo"
7+
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
8+
mc:Ignorable="d"
9+
d:DesignHeight="300" d:DesignWidth="600" Background="Transparent">
10+
<UserControl.Resources>
11+
<Border x:Key="dialogContent" Margin="8">
12+
<StackPanel Orientation="Vertical">
13+
<TextBlock Text="So you clicked on the button. Did you really got it?" />
14+
<Button Content="OK" Margin="0,16,0,0" IsDefault="True" HorizontalAlignment="Right" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" Style="{DynamicResource MaterialDesignFlatButton}" />
15+
</StackPanel>
16+
</Border>
17+
</UserControl.Resources>
18+
<Grid>
19+
<ScrollViewer HorizontalAlignment="Stretch" HorizontalScrollBarVisibility="Auto" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto">
20+
<Grid>
21+
<Grid.ColumnDefinitions>
22+
<ColumnDefinition Width="250" />
23+
<ColumnDefinition Width="250" />
24+
<ColumnDefinition Width="250" />
25+
<ColumnDefinition Width="300" />
26+
</Grid.ColumnDefinitions>
27+
<Grid.RowDefinitions>
28+
<RowDefinition Height="auto" />
29+
<RowDefinition Height="16" />
30+
<RowDefinition Height="auto" />
31+
<RowDefinition Height="16" />
32+
<RowDefinition Height="100*" />
33+
</Grid.RowDefinitions>
34+
<TextBlock Margin="8,0" Text="Click the button to show a simple Snackbar by setting the Content property." TextWrapping="WrapWithOverflow" />
35+
<Button Grid.Row="2" Content="SHOW" Width="80" Click="ShowSimpleSnackbarButtonClickHandler" />
36+
<TextBlock Grid.Column="1" Margin="8,0" Text="This button shows a Snackbar with an action by setting the ActionLabel Property. The action will show another Snackbar after a short delay." TextWrapping="WrapWithOverflow" />
37+
<Button Grid.Column="1" Grid.Row="2" Content="SHOW" Width="80" Click="ShowSnackbarButtonClickHandler" />
38+
<TextBlock Grid.Column="2" Margin="8,0" Text="A click on the button shows a multiline Snackbar." TextWrapping="WrapWithOverflow" />
39+
<Button Grid.Column="2" Grid.Row="2" Content="SHOW" Width="80" Click="ShowMultilineSnackbarButtonClickHandler" />
40+
<TextBlock Grid.Column="3" Margin="8,0" Text="By setting the Mode property to Manual you have the full control over the visibility. You just need to set the IsOpen property. Have a look in the XAML." TextWrapping="WrapWithOverflow" />
41+
<ToggleButton Grid.Column="3" Grid.Row="2" x:Name="manualToggle" HorizontalAlignment="Center" />
42+
43+
<materialDesign:Snackbar Grid.ColumnSpan="3" Grid.Row="4" x:Name="snackbar" Mode="HalfAutomatic" ActionClick="SnackbarActionClickHandler" />
44+
<!-- properties will be set in the order in the xaml, so set the Mode property first for the manual mode -->
45+
<materialDesign:Snackbar Grid.Column="3" Grid.Row="4" x:Name="manualSnackbar" Mode="Manual" Content="This is a manually controlled Snackbar." IsOpen="{Binding Path=IsChecked, Mode=TwoWay}" />
46+
</Grid>
47+
</ScrollViewer>
48+
</Grid>
49+
</UserControl>

MainDemo.Wpf/Snackbar.xaml.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
16+
using MaterialDesignThemes.Wpf;
17+
18+
namespace MaterialDesignColors.WpfExample
19+
{
20+
public partial class Snackbar : UserControl
21+
{
22+
private enum SnackbarDemoMode
23+
{
24+
Simple,
25+
ShowSecondAfterDelay,
26+
Multiline
27+
}
28+
29+
private SnackbarDemoMode? _mode;
30+
31+
public Snackbar()
32+
{
33+
_mode = null;
34+
35+
InitializeComponent();
36+
37+
manualSnackbar.DataContext = manualToggle;
38+
}
39+
40+
private void ShowSimpleSnackbarButtonClickHandler(object sender, RoutedEventArgs args)
41+
{
42+
_mode = SnackbarDemoMode.Simple;
43+
44+
snackbar.ActionLabel = null;
45+
snackbar.VisibilityTimeout = 3000;
46+
47+
// .NET caches and reuses string constants
48+
// without explicitly create a new string object, calling the setter will not raise a property changed after the second call
49+
// (reference to same string in memory)
50+
snackbar.Content = new string("This is a simple Snackbar.".ToCharArray());
51+
}
52+
53+
private void ShowSnackbarButtonClickHandler(object sender, RoutedEventArgs args)
54+
{
55+
_mode = SnackbarDemoMode.ShowSecondAfterDelay;
56+
57+
snackbar.ActionLabel = "HELLO";
58+
snackbar.VisibilityTimeout = 3000;
59+
snackbar.Content = new string("Hello from the Snackbar!".ToCharArray());
60+
}
61+
62+
private void ShowMultilineSnackbarButtonClickHandler(object sender, RoutedEventArgs args)
63+
{
64+
_mode = SnackbarDemoMode.Multiline;
65+
66+
snackbar.ActionLabel = "GOT IT";
67+
snackbar.VisibilityTimeout = 6000;
68+
snackbar.Content = new string("The specs says that the maximum width should be 568dp. However there sould be at most only two lines of text.".ToCharArray());
69+
}
70+
71+
private async void SnackbarActionClickHandler(object sender, RoutedEventArgs args)
72+
{
73+
if (_mode == SnackbarDemoMode.Simple || _mode == SnackbarDemoMode.Multiline)
74+
{
75+
await DialogHost.Show(Resources["dialogContent"], "RootDialog");
76+
}
77+
else if (_mode == SnackbarDemoMode.ShowSecondAfterDelay)
78+
{
79+
await Task.Delay(2000);
80+
81+
_mode = null;
82+
83+
snackbar.ActionLabel = "BYE";
84+
snackbar.Content = new string("A second hello from the Snackbar!".ToCharArray());
85+
}
86+
}
87+
}
88+
}

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@
230230
<Generator>MSBuild:Compile</Generator>
231231
<SubType>Designer</SubType>
232232
</Page>
233+
<Page Include="Themes\MaterialDesignTheme.Snackbar.xaml">
234+
<SubType>Designer</SubType>
235+
<Generator>MSBuild:Compile</Generator>
236+
</Page>
233237
</ItemGroup>
234238
<ItemGroup>
235239
<Compile Include="Card.cs" />
@@ -290,6 +294,7 @@
290294
<Compile Include="IconType.cs" />
291295
<Compile Include="ListBoxAssist.cs" />
292296
<Compile Include="Palette.cs" />
297+
<Compile Include="Snackbar.cs" />
293298
<Compile Include="Transitions\CircleWipe.cs" />
294299
<Compile Include="IHintProxy.cs" />
295300
<Compile Include="Transitions\IndexedItemOffsetMultiplierExtension.cs" />

0 commit comments

Comments
 (0)