Skip to content

Commit 26aeed8

Browse files
committed
restore and enhance snackbar styling. still issues when user rsizes window
1 parent 06e7c52 commit 26aeed8

File tree

9 files changed

+199
-544
lines changed

9 files changed

+199
-544
lines changed

MainDemo.Wpf/ProvingGround.xaml

Lines changed: 67 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</ResourceDictionary.MergedDictionaries>
2525

2626

27-
27+
2828
<Style TargetType="{x:Type provingGroundStuff:MeasuringTextBox}" BasedOn="{StaticResource MaterialDesignTextBox}" />
2929

3030

@@ -33,70 +33,90 @@
3333
</UserControl.Resources>
3434

3535
<Grid HorizontalAlignment="Left">
36-
<Grid.RowDefinitions>
37-
<RowDefinition />
38-
<RowDefinition />
39-
</Grid.RowDefinitions>
4036
<Grid.ColumnDefinitions>
4137
<ColumnDefinition />
4238
<ColumnDefinition />
4339
<ColumnDefinition />
4440
<ColumnDefinition />
4541
</Grid.ColumnDefinitions>
46-
42+
<Grid.RowDefinitions>
43+
<RowDefinition />
44+
<RowDefinition />
45+
</Grid.RowDefinitions>
46+
4747
<!-- example 1 -->
48-
<!-- simplest form -->
49-
<materialDesign:Snackbar2 Message="hello 1"
50-
IsActive="False"
51-
x:Name="SnackbarOne" />
52-
53-
<ToggleButton IsChecked="{Binding ElementName=SnackbarOne, Path=IsActive, Mode=TwoWay}"
54-
Grid.Row="1" Grid.Column="0" />
48+
<Border Background="{DynamicResource MaterialDesignSelection}" Grid.RowSpan="2"
49+
Padding="8 0 8 0">
50+
<Grid>
51+
<ToggleButton IsChecked="{Binding ElementName=SnackbarOne, Path=IsActive, Mode=TwoWay}" />
5552

56-
<!-- example 2 -->
57-
<!-- long hand form for setting the message -->
58-
<materialDesign:Snackbar2 IsActive="True"
59-
Grid.Row="0"
60-
Grid.Column="1"
61-
x:Name="SnackbarTwo" >
62-
<materialDesign:SnackbarMessage Content="Hello 2" ActionContent="UNDO" />
63-
</materialDesign:Snackbar2>
64-
65-
<ToggleButton IsChecked="{Binding ElementName=SnackbarTwo, Path=IsActive, Mode=TwoWay}"
66-
Grid.Row="1" Grid.Column="1" />
53+
<!-- simplest form -->
54+
<materialDesign:Snackbar2 Message="hello 1"
55+
IsActive="False"
56+
x:Name="SnackbarOne" />
57+
</Grid>
58+
</Border>
6759

60+
<!-- example 2 -->
61+
<Border Background="{DynamicResource MaterialDesignPaper}"
62+
Padding="8 0 8 0"
63+
Grid.Column="1">
64+
<Grid>
65+
<ToggleButton IsChecked="{Binding ElementName=SnackbarTwo, Path=IsActive, Mode=TwoWay}" />
66+
<!-- long hand form for setting the message -->
67+
<materialDesign:Snackbar2 IsActive="False"
68+
x:Name="SnackbarTwo" >
69+
<materialDesign:SnackbarMessage Content="Hello 2" ActionContent="UNDO" />
70+
</materialDesign:Snackbar2>
71+
</Grid>
72+
</Border>
6873

69-
<!-- example 3 -->
70-
<!--
74+
<!-- example 3 -->
75+
<!--
7176
* using a message queue to manage queuing of messages, and getting onto correct thread
7277
* notice the shorthand syntax {materialDesign:MessageQueue} for creating a new message
7378
queue without expanded XAML. useful in code-behind scenarios if you dont want to bind
7479
a message queue in to the snackbar.
7580
-->
76-
<materialDesign:Snackbar2 MessageQueue="{materialDesign:MessageQueue}"
77-
Grid.Row="0"
78-
Grid.Column="2"
79-
x:Name="SnackbarThree" />
80-
81-
<StackPanel Orientation="Horizontal"
82-
Grid.Row="1"
83-
Grid.Column="2">
84-
<TextBlock HorizontalAlignment="Center">Message: </TextBlock>
85-
<TextBox x:Name="MessageTextBox" HorizontalAlignment="Center">Hello World</TextBox>
86-
<Button Click="SnackBar3_OnClick" HorizontalAlignment="Center">Send</Button>
87-
</StackPanel>
81+
<Border Background="{DynamicResource MaterialDesignSelection}"
82+
Padding="8 0 8 0"
83+
Grid.Column="2">
84+
<Grid>
85+
<StackPanel Orientation="Horizontal">
86+
<TextBlock HorizontalAlignment="Center">Message:</TextBlock>
87+
<TextBox x:Name="MessageTextBox" HorizontalAlignment="Center">Hello World</TextBox>
88+
<Button Click="SnackBar3_OnClick" HorizontalAlignment="Center">Send</Button>
89+
</StackPanel>
90+
<materialDesign:Snackbar2 MessageQueue="{materialDesign:MessageQueue}"
91+
x:Name="SnackbarThree" />
92+
</Grid>
93+
</Border>
8894

8995
<!-- example 4 -->
90-
<!-- uses some action command call backs -->
91-
<materialDesign:Snackbar2 MessageQueue="{materialDesign:MessageQueue}"
92-
Grid.Row="0"
93-
Grid.Column="3"
94-
x:Name="SnackbarFour" />
95-
96-
<Button Click="SnackBar4_OnClick" HorizontalAlignment="Center"
97-
Grid.Row="1" Grid.Column="3"
98-
>Send</Button>
96+
<!-- uses some action command call backs -->
97+
<Border Background="{DynamicResource MaterialDesignPaper}"
98+
Padding="8 0 8 0"
99+
Grid.Column="3">
100+
<Grid>
101+
<materialDesign:Snackbar2 MessageQueue="{materialDesign:MessageQueue}"
102+
x:Name="SnackbarFour" />
103+
<Button Click="SnackBar4_OnClick" HorizontalAlignment="Center">Send</Button>
104+
</Grid>
105+
</Border>
99106

107+
<Border Background="{DynamicResource MaterialDesignSelection}"
108+
Grid.ColumnSpan="4"
109+
Grid.Row="1">
110+
<StackPanel VerticalAlignment="Bottom">
111+
<ToggleButton IsChecked="{Binding ElementName=SnackbarFive, Path=IsActive, Mode=TwoWay}"
112+
Margin="0 0 0 24"/>
113+
<materialDesign:Snackbar2 HorizontalAlignment="Stretch"
114+
x:Name="SnackbarFive">
115+
<materialDesign:SnackbarMessage Content="This Snackbar is stretched horizontally. You should ensure your content is pushed up."
116+
ActionContent="OK" />
117+
</materialDesign:Snackbar2>
118+
</StackPanel>
119+
</Border>
100120

101121
</Grid>
102122

MainDemo.Wpf/Snackbar.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@
4040
<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" />
4141
<ToggleButton Grid.Column="3" Grid.Row="2" x:Name="manualToggle" HorizontalAlignment="Center" />
4242

43+
<!--
4344
<materialDesign:Snackbar Grid.ColumnSpan="3" Grid.Row="4" x:Name="snackbar" Mode="HalfAutomatic" ActionClick="SnackbarActionClickHandler" />
45+
-->
4446
<!-- properties will be set in the order in the xaml, so set the Mode property first for the manual mode -->
47+
<!--
4548
<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}" />
49+
-->
4650
</Grid>
4751
</ScrollViewer>
4852
</Grid>

MainDemo.Wpf/Snackbar.xaml.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,38 @@ public Snackbar()
3434

3535
InitializeComponent();
3636

37-
manualSnackbar.DataContext = manualToggle;
37+
//manualSnackbar.DataContext = manualToggle;
3838
}
3939

4040
private void ShowSimpleSnackbarButtonClickHandler(object sender, RoutedEventArgs args)
4141
{
4242
_mode = SnackbarDemoMode.Simple;
4343

44-
snackbar.ActionLabel = null;
45-
snackbar.VisibilityTimeout = 3000;
44+
//snackbar.ActionLabel = null;
45+
//snackbar.VisibilityTimeout = 3000;
4646

4747
// .NET caches and reuses string constants
4848
// without explicitly create a new string object, calling the setter will not raise a property changed after the second call
4949
// (reference to same string in memory)
50-
snackbar.Content = new string("This is a simple Snackbar.".ToCharArray());
50+
//snackbar.Content = new string("This is a simple Snackbar.".ToCharArray());
5151
}
5252

5353
private void ShowSnackbarButtonClickHandler(object sender, RoutedEventArgs args)
5454
{
5555
_mode = SnackbarDemoMode.ShowSecondAfterDelay;
5656

57-
snackbar.ActionLabel = "HELLO";
58-
snackbar.VisibilityTimeout = 3000;
59-
snackbar.Content = new string("Hello from the Snackbar!".ToCharArray());
57+
//snackbar.ActionLabel = "HELLO";
58+
//snackbar.VisibilityTimeout = 3000;
59+
//snackbar.Content = new string("Hello from the Snackbar!".ToCharArray());
6060
}
6161

6262
private void ShowMultilineSnackbarButtonClickHandler(object sender, RoutedEventArgs args)
6363
{
6464
_mode = SnackbarDemoMode.Multiline;
6565

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());
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());
6969
}
7070

7171
private async void SnackbarActionClickHandler(object sender, RoutedEventArgs args)
@@ -80,8 +80,8 @@ private async void SnackbarActionClickHandler(object sender, RoutedEventArgs arg
8080

8181
_mode = null;
8282

83-
snackbar.ActionLabel = "BYE";
84-
snackbar.Content = new string("A second hello from the Snackbar!".ToCharArray());
83+
//snackbar.ActionLabel = "BYE";
84+
//snackbar.Content = new string("A second hello from the Snackbar!".ToCharArray());
8585
}
8686
}
8787
}

0 commit comments

Comments
 (0)