Skip to content

Commit b5e87f3

Browse files
committed
Successfully injected XamlDisplayerPanel into Snackbars.xaml
1 parent 3af623d commit b5e87f3

File tree

2 files changed

+25
-48
lines changed

2 files changed

+25
-48
lines changed

MainDemo.Wpf/Snackbars.xaml

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,75 +5,56 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:local="clr-namespace:MaterialDesignDemo"
77
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
8+
xmlns:codeDisplayer="clr-namespace:CodeDisplayer;assembly=CodeDisplayer"
89
mc:Ignorable="d"
910
d:DesignHeight="300" d:DesignWidth="300">
1011

1112
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden">
12-
<Grid Margin="0 0 0 4">
13-
<Grid.ColumnDefinitions>
14-
<ColumnDefinition Width="340" />
15-
<ColumnDefinition Width="340" />
16-
<ColumnDefinition Width="340" />
17-
<ColumnDefinition Width="340" />
18-
</Grid.ColumnDefinitions>
19-
<Grid.RowDefinitions>
20-
<RowDefinition />
21-
<RowDefinition />
22-
</Grid.RowDefinitions>
23-
24-
<!-- example 1 -->
13+
<codeDisplayer:XamlDisplayerPanel x:Name="XamlDisplayerPanel" Margin="0 0 0 4">
2514
<Border Background="{DynamicResource MaterialDesignSelection}"
2615
Padding="8 0 8 0">
27-
<Grid>
16+
<Grid Height="200">
2817
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
2918
<TextBlock TextWrapping="WrapWithOverflow" Style="{DynamicResource MaterialDesignSubheadingTextBlock}">Example 1.</TextBlock>
3019
<TextBlock TextWrapping="WrapWithOverflow" >Simple definition within XAML. Use the toggle to display the message.</TextBlock>
31-
<ToggleButton IsChecked="{Binding ElementName=SnackbarOne, Path=IsActive, Mode=TwoWay}"
20+
<ToggleButton x:Name="ToggleButton1"
3221
Margin="0 8 0 0"/>
3322
</StackPanel>
34-
35-
3623
<!-- simplest form -->
3724
<materialDesign:Snackbar Message="hello 1"
38-
IsActive="False"
39-
x:Name="SnackbarOne" />
25+
IsActive="{Binding ElementName=ToggleButton1, Path=IsChecked}"
26+
Width="300"/>
4027
</Grid>
4128
</Border>
4229

43-
<!-- example 2 -->
44-
<Border Background="{DynamicResource MaterialDesignPaper}"
45-
Padding="8 0 8 0"
46-
Grid.Column="1">
30+
<Border Background="{DynamicResource MaterialDesignPaper}" Height="200"
31+
Padding="8 0 8 0">
4732
<Grid>
4833
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
4934
<TextBlock TextWrapping="WrapWithOverflow" Style="{DynamicResource MaterialDesignSubheadingTextBlock}">Example 2.</TextBlock>
5035
<TextBlock TextWrapping="WrapWithOverflow" >View source to see message defined in long hand, allowing action button content to be set.</TextBlock>
51-
<ToggleButton IsChecked="{Binding ElementName=SnackbarTwo, Path=IsActive, Mode=TwoWay}"
36+
<ToggleButton x:Name="ToggleButton2"
5237
Margin="0 8 0 0" />
5338
</StackPanel>
54-
5539
<!-- long hand form for setting the message -->
56-
<materialDesign:Snackbar IsActive="False"
57-
x:Name="SnackbarTwo" >
40+
<materialDesign:Snackbar IsActive="{Binding ElementName=ToggleButton2, Path=IsChecked}">
5841
<materialDesign:SnackbarMessage Content="Hello 2" ActionContent="UNDO" />
5942
</materialDesign:Snackbar>
6043
</Grid>
6144
</Border>
6245

63-
<!-- example 3 -->
64-
<!--
46+
<Border Background="{DynamicResource MaterialDesignSelection}"
47+
Padding="8 0 8 0">
48+
<!--
6549
* using a message queue to manage queuing of messages, and getting onto correct thread
6650
* notice the shorthand syntax {materialDesign:MessageQueue} for creating a new message
6751
queue without expanded XAML. useful in code-behind scenarios if you dont want to bind
6852
a message queue in to the snackbar.
6953
-->
70-
<Border Background="{DynamicResource MaterialDesignSelection}"
71-
Padding="8 0 8 0"
72-
Grid.Column="2">
7354
<Grid>
7455
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
7556
<TextBlock TextWrapping="WrapWithOverflow" Style="{DynamicResource MaterialDesignSubheadingTextBlock}">Example 3.</TextBlock>
76-
<TextBlock TextWrapping="WrapWithOverflow">In many real world scenario, notification display must deal with threading, queuing, and potentially heavy usage. A MessageQueue can be set to handle much of this for you, gicing the following benefits:</TextBlock>
57+
<TextBlock TextWrapping="WrapWithOverflow" MaxWidth="300">In many real world scenario, notification display must deal with threading, queuing, and potentially heavy usage. A MessageQueue can be set to handle much of this for you, gicing the following benefits:</TextBlock>
7758
<TextBlock TextWrapping="WrapWithOverflow" Margin="0 8 0 0" Text=" • Messages can be queued from any thread"/>
7859
<TextBlock TextWrapping="WrapWithOverflow" Text=" • Message will auto hide after a time out period"/>
7960
<TextBlock TextWrapping="WrapWithOverflow" Text=" • Notification will not time out if mouse is over it"/>
@@ -99,15 +80,13 @@
9980
</Grid>
10081
</Border>
10182

102-
<!-- example 4 -->
103-
<!-- illustrates queueing uses some action command call backs -->
10483
<Border Background="{DynamicResource MaterialDesignPaper}"
105-
Padding="8 0 8 0"
106-
Grid.Column="3">
84+
Padding="8 0 8 0">
85+
<!-- illustrates queueing uses some action command call backs -->
10786
<Grid>
10887
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
10988
<TextBlock TextWrapping="WrapWithOverflow" Style="{DynamicResource MaterialDesignSubheadingTextBlock}">Example 4.</TextBlock>
110-
<TextBlock TextWrapping="WrapWithOverflow">Illustrates queueing (including discarding of duplicates), and handling of commands. Action a notification to see a System.Trace response..</TextBlock>
89+
<TextBlock TextWrapping="WrapWithOverflow" MaxWidth="300">Illustrates queueing (including discarding of duplicates), and handling of commands. Action a notification to see a System.Trace response..</TextBlock>
11190
<Grid Margin="0 16 0 0">
11291
<Grid.ColumnDefinitions>
11392
<ColumnDefinition Width="*" />
@@ -123,30 +102,25 @@
123102
</Grid>
124103
</Border>
125104

126-
<!-- example 5 -->
105+
<Border Background="{DynamicResource MaterialDesignChipBackground}" Height="300">
127106
<!-- full width snack bar -->
128-
<Border Background="{DynamicResource MaterialDesignChipBackground}"
129-
Grid.ColumnSpan="2"
130-
Grid.Row="1">
131107
<StackPanel VerticalAlignment="Bottom">
132108
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"
133109
Margin="0 0 0 32">
134110
<TextBlock TextWrapping="WrapWithOverflow" Style="{DynamicResource MaterialDesignSubheadingTextBlock}">Example 5.</TextBlock>
135111
<TextBlock TextWrapping="WrapWithOverflow">Illustrates a full width Snackbar.</TextBlock>
136-
<ToggleButton IsChecked="{Binding ElementName=SnackbarFive, Path=IsActive, Mode=TwoWay}"
112+
<ToggleButton x:Name="ToggleButton3"
137113
Margin="0 8 0 0" />
138114
</StackPanel>
139-
<materialDesign:Snackbar HorizontalAlignment="Stretch"
140-
x:Name="SnackbarFive">
115+
<materialDesign:Snackbar HorizontalAlignment="Stretch" IsActive="{Binding ElementName=ToggleButton3, Path=IsChecked}">
141116
<materialDesign:SnackbarMessage Content="This Snackbar is stretched horizontally. Consider allowing your content to push up."
142117
ActionContent="OK" />
143118
</materialDesign:Snackbar>
144119
</StackPanel>
145120
</Border>
146121

147-
<!-- example 6 -->
122+
<Border>
148123
<!-- colour variations -->
149-
<Border Grid.Column="2" Grid.Row="1">
150124
<Border.Resources>
151125
<ResourceDictionary>
152126
<ResourceDictionary.MergedDictionaries>
@@ -182,6 +156,6 @@
182156
</materialDesign:Snackbar>
183157
</StackPanel>
184158
</Border>
185-
</Grid>
159+
</codeDisplayer:XamlDisplayerPanel>
186160
</ScrollViewer>
187161
</UserControl>

MainDemo.Wpf/Snackbars.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
using System.Windows.Media.Imaging;
1414
using System.Windows.Navigation;
1515
using System.Windows.Shapes;
16+
using CodeDisplayer;
17+
using MaterialDesignDemo.Helper;
1618

1719
namespace MaterialDesignDemo
1820
{
@@ -24,6 +26,7 @@ public partial class Snackbars : UserControl
2426
public Snackbars()
2527
{
2628
InitializeComponent();
29+
XamlDisplayerPanel.Initialize(new SourceRouter(this.GetType().Name).GetSource());
2730
}
2831

2932
private void SnackBar3_OnClick(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)