Skip to content

Commit 8e6eb97

Browse files
committed
more dialog usage patterns
1 parent cff6a62 commit 8e6eb97

File tree

8 files changed

+253
-118
lines changed

8 files changed

+253
-118
lines changed

MainDemo.Wpf/App.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
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+
xmlns:system="clr-namespace:System;assembly=mscorlib"
5+
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
46
StartupUri="MainWindow.xaml">
57
<Application.Resources>
68
<ResourceDictionary>
79
<ResourceDictionary.MergedDictionaries>
8-
10+
911
<!-- Material -->
1012
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
1113
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
1214
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
1315
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
1416

15-
</ResourceDictionary.MergedDictionaries>
17+
</ResourceDictionary.MergedDictionaries>
1618
</ResourceDictionary>
1719
</Application.Resources>
1820
</Application>

MainDemo.Wpf/Dialogs.xaml

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@
3636
<Grid.ColumnDefinitions>
3737
<ColumnDefinition Width="1*" />
3838
<ColumnDefinition Width="1*" />
39+
<ColumnDefinition Width="1*" />
40+
<ColumnDefinition Width="1*" />
3941
</Grid.ColumnDefinitions>
4042

43+
<!--#region SAMPLE 1-->
4144
<TextBlock TextWrapping="Wrap" HorizontalAlignment="Center"
42-
Margin="16">SAMPLE 1: Dialog encapsulating specific content, launched from a routed command, response handled in code-behind.</TextBlock>
43-
<wpf:DialogHost DialogClosing="DialogHost_OnDialogClosing"
45+
Margin="16">SAMPLE 1: Localised dialog encapsulating specific content, launched from a routed command, response handled in code-behind.</TextBlock>
46+
<wpf:DialogHost DialogClosing="Sample1_DialogHost_OnDialogClosing"
4447
Grid.Column="0" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center">
4548
<wpf:DialogHost.DialogContent>
4649
<StackPanel Margin="16">
@@ -96,6 +99,36 @@
9699
</Grid>
97100
</Border>
98101
</wpf:DialogHost>
102+
<!--#endregion -->
103+
104+
<!--#region SAMPLE 2-->
105+
<TextBlock Grid.Column="1" Grid.Row="0" TextWrapping="Wrap">SAMPLE 2: Using OpenDialog, passing content via the Parameter. You can pass a view model, provided a corresponding DataTemplate can be found in the scope of the root DialogHost.</TextBlock>
106+
<StackPanel Grid.Column="1" Grid.Row="1">
107+
<!--the request to open the dialog will bubble up to the top-most DialogHost, but we can used the attached property based event to handle the response -->
108+
<Button Command="{x:Static wpf:DialogHost.OpenDialogCommand}"
109+
wpf:DialogHost.DialogClosing="Sample2_DialogHost_OnDialogClosing"
110+
Width="128">
111+
<Button.CommandParameter>
112+
<StackPanel Margin="16">
113+
<ProgressBar Style="{DynamicResource MaterialDesignCircularProgressBar}" HorizontalAlignment="Center" Margin="16" IsIndeterminate="True" Value="0" />
114+
<Button Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True"
115+
Command="{x:Static wpf:DialogHost.CloseDialogCommand}"
116+
CommandParameter="Sample2Cancel"
117+
HorizontalAlignment="Center">CANCEL</Button>
118+
</StackPanel>
119+
</Button.CommandParameter>
120+
PASS VIEW
121+
</Button>
122+
<Button Command="{x:Static wpf:DialogHost.OpenDialogCommand}"
123+
Width="128" Margin="0 32 0 0">
124+
<Button.CommandParameter>
125+
<!-- the simplest view model of all, a DateTime. the view can be found in the resources of MainWindow.xaml -->
126+
<system:DateTime>1966-JUL-30</system:DateTime>
127+
</Button.CommandParameter>
128+
PASS MODEL
129+
</Button>
130+
</StackPanel>
131+
<!--#endregion-->
99132
</Grid>
100133
</Grid>
101134
</UserControl>

MainDemo.Wpf/Dialogs.xaml.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public Dialogs()
2626
InitializeComponent();
2727
}
2828

29-
private void DialogHost_OnDialogClosing(object sender, DialogClosingEventArgs eventArgs)
29+
private void Sample1_DialogHost_OnDialogClosing(object sender, DialogClosingEventArgs eventArgs)
3030
{
31-
Console.WriteLine("Closing dialog with parameter: " + (eventArgs.Parameter ?? ""));
31+
Console.WriteLine("SAMPLE 1: Closing dialog with parameter: " + (eventArgs.Parameter ?? ""));
3232

3333
//you can cancel the dialog close:
3434
//eventArgs.Cancel();
@@ -38,5 +38,10 @@ private void DialogHost_OnDialogClosing(object sender, DialogClosingEventArgs ev
3838
if (!string.IsNullOrWhiteSpace(FruitTextBox.Text))
3939
FruitListBox.Items.Add(FruitTextBox.Text.Trim());
4040
}
41+
42+
private void Sample2_DialogHost_OnDialogClosing(object sender, DialogClosingEventArgs eventArgs)
43+
{
44+
Console.WriteLine("SAMPLE 2: Closing dialog with parameter: " + (eventArgs.Parameter ?? ""));
45+
}
4146
}
4247
}

MainDemo.Wpf/MainWindow.xaml

Lines changed: 109 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xmlns:wpfExample="clr-namespace:MaterialDesignColors.WpfExample"
55
xmlns:domain="clr-namespace:MaterialDesignColors.WpfExample.Domain"
66
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
7+
xmlns:system="clr-namespace:System;assembly=mscorlib"
78
Title="Material Design in XAML" Height="800" Width="1100"
89
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
910
TextElement.FontWeight="Medium"
@@ -19,104 +20,115 @@
1920
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToggleButton.xaml" />
2021
</ResourceDictionary.MergedDictionaries>
2122
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
23+
24+
<!-- data template used for the dialogs example, defines a View for a ViewModel of type DateTime -->
25+
<DataTemplate DataType="{x:Type system:DateTime}">
26+
<StackPanel Margin="16">
27+
<TextBlock>England win the World Cup:</TextBlock>
28+
<TextBlock Margin="0 8 0 0" Text="{Binding }" />
29+
<TextBlock Margin="0 8 0 0" >You will never see that again.</TextBlock>
30+
<Button Margin="0 8 0 0" IsDefault="True" Command="{x:Static wpf:DialogHost.CloseDialogCommand}" Style="{DynamicResource MaterialDesignFlatButton}">AWESOME</Button>
31+
</StackPanel>
32+
</DataTemplate>
2233
</ResourceDictionary>
2334
</Window.Resources>
2435

25-
<DockPanel>
26-
<wpf:ColorZone Padding="16" Effect="{StaticResource MaterialDesignShadowDepth2}"
27-
Mode="PrimaryMid" DockPanel.Dock="Top">
28-
<DockPanel>
29-
<ToggleButton Style="{StaticResource MaterialDesignHamburgerToggleButton}" IsChecked="True"
30-
x:Name="MenuToggleButton"/>
31-
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="22">Material Design In XAML Toolkit</TextBlock>
32-
</DockPanel>
33-
</wpf:ColorZone>
34-
<ListBox DockPanel.Dock="Left" x:Name="DemoItemsListBox" Margin="16 16 0 16" SelectedIndex="0"
35-
Visibility="{Binding ElementName=MenuToggleButton, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}">
36-
<ListBox.ItemTemplate>
37-
<DataTemplate DataType="domain:DemoItem">
38-
<TextBlock Text="{Binding Name}" />
39-
</DataTemplate>
40-
</ListBox.ItemTemplate>
41-
<domain:DemoItem Name="Home">
42-
<domain:DemoItem.Content>
43-
<wpfExample:Home />
44-
</domain:DemoItem.Content>
45-
</domain:DemoItem>
46-
<domain:DemoItem Name="Palette">
47-
<domain:DemoItem.Content>
48-
<wpfExample:PaletteSelector>
49-
<wpfExample:PaletteSelector.DataContext>
50-
<wpfExample:PaletteSelectorViewModel />
51-
</wpfExample:PaletteSelector.DataContext>
52-
</wpfExample:PaletteSelector>
53-
</domain:DemoItem.Content>
54-
</domain:DemoItem>
55-
<domain:DemoItem Name="Buttons &amp; Toggles">
56-
<domain:DemoItem.Content>
57-
<wpfExample:Buttons />
58-
</domain:DemoItem.Content>
59-
</domain:DemoItem>
60-
<domain:DemoItem Name="Fields">
61-
<domain:DemoItem.Content>
62-
<wpfExample:TextFields />
63-
</domain:DemoItem.Content>
64-
</domain:DemoItem>
65-
<domain:DemoItem Name="Cards">
66-
<domain:DemoItem.Content>
67-
<wpfExample:Cards />
68-
</domain:DemoItem.Content>
69-
</domain:DemoItem>
70-
<domain:DemoItem Name="Colour Zones">
71-
<domain:DemoItem.Content>
72-
<wpfExample:ColorZones />
73-
</domain:DemoItem.Content>
74-
</domain:DemoItem>
75-
<domain:DemoItem Name="Lists">
76-
<domain:DemoItem.Content>
77-
<wpfExample:Lists>
78-
<wpfExample:Lists.DataContext>
79-
<domain:ListsAndGridsViewModel />
80-
</wpfExample:Lists.DataContext>
81-
</wpfExample:Lists>
82-
</domain:DemoItem.Content>
83-
</domain:DemoItem>
84-
<domain:DemoItem Name="Trees">
85-
<domain:DemoItem.Content>
86-
<wpfExample:Trees />
87-
</domain:DemoItem.Content>
88-
</domain:DemoItem>
89-
<domain:DemoItem Name="Grids">
90-
<domain:DemoItem.Content>
91-
<wpfExample:Grids>
92-
<wpfExample:Grids.DataContext>
93-
<domain:ListsAndGridsViewModel />
94-
</wpfExample:Grids.DataContext>
95-
</wpfExample:Grids>
96-
</domain:DemoItem.Content>
97-
</domain:DemoItem>
98-
<domain:DemoItem Name="Menus &amp; Tool Bars">
99-
<domain:DemoItem.Content>
100-
<wpfExample:MenusAndToolBars />
101-
</domain:DemoItem.Content>
102-
</domain:DemoItem>
103-
<domain:DemoItem Name="Progress Indicators">
104-
<domain:DemoItem.Content>
105-
<wpfExample:Progress />
106-
</domain:DemoItem.Content>
107-
</domain:DemoItem>
108-
<domain:DemoItem Name="Dialogs">
109-
<domain:DemoItem.Content>
110-
<wpfExample:Dialogs />
111-
</domain:DemoItem.Content>
112-
</domain:DemoItem>
113-
<domain:DemoItem Name="Shadows">
114-
<domain:DemoItem.Content>
115-
<wpfExample:Shadows />
116-
</domain:DemoItem.Content>
117-
</domain:DemoItem>
118-
</ListBox>
119-
<ContentControl Margin="16" Content="{Binding ElementName=DemoItemsListBox, Path=SelectedItem.Content}" />
120-
</DockPanel>
121-
36+
<wpf:DialogHost>
37+
<DockPanel>
38+
<wpf:ColorZone Padding="16" Effect="{StaticResource MaterialDesignShadowDepth2}"
39+
Mode="PrimaryMid" DockPanel.Dock="Top">
40+
<DockPanel>
41+
<ToggleButton Style="{StaticResource MaterialDesignHamburgerToggleButton}" IsChecked="True"
42+
x:Name="MenuToggleButton"/>
43+
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="22">Material Design In XAML Toolkit</TextBlock>
44+
</DockPanel>
45+
</wpf:ColorZone>
46+
<ListBox DockPanel.Dock="Left" x:Name="DemoItemsListBox" Margin="16 16 0 16" SelectedIndex="0"
47+
Visibility="{Binding ElementName=MenuToggleButton, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}">
48+
<ListBox.ItemTemplate>
49+
<DataTemplate DataType="domain:DemoItem">
50+
<TextBlock Text="{Binding Name}" />
51+
</DataTemplate>
52+
</ListBox.ItemTemplate>
53+
<domain:DemoItem Name="Home">
54+
<domain:DemoItem.Content>
55+
<wpfExample:Home />
56+
</domain:DemoItem.Content>
57+
</domain:DemoItem>
58+
<domain:DemoItem Name="Palette">
59+
<domain:DemoItem.Content>
60+
<wpfExample:PaletteSelector>
61+
<wpfExample:PaletteSelector.DataContext>
62+
<wpfExample:PaletteSelectorViewModel />
63+
</wpfExample:PaletteSelector.DataContext>
64+
</wpfExample:PaletteSelector>
65+
</domain:DemoItem.Content>
66+
</domain:DemoItem>
67+
<domain:DemoItem Name="Buttons &amp; Toggles">
68+
<domain:DemoItem.Content>
69+
<wpfExample:Buttons />
70+
</domain:DemoItem.Content>
71+
</domain:DemoItem>
72+
<domain:DemoItem Name="Fields">
73+
<domain:DemoItem.Content>
74+
<wpfExample:TextFields />
75+
</domain:DemoItem.Content>
76+
</domain:DemoItem>
77+
<domain:DemoItem Name="Cards">
78+
<domain:DemoItem.Content>
79+
<wpfExample:Cards />
80+
</domain:DemoItem.Content>
81+
</domain:DemoItem>
82+
<domain:DemoItem Name="Colour Zones">
83+
<domain:DemoItem.Content>
84+
<wpfExample:ColorZones />
85+
</domain:DemoItem.Content>
86+
</domain:DemoItem>
87+
<domain:DemoItem Name="Lists">
88+
<domain:DemoItem.Content>
89+
<wpfExample:Lists>
90+
<wpfExample:Lists.DataContext>
91+
<domain:ListsAndGridsViewModel />
92+
</wpfExample:Lists.DataContext>
93+
</wpfExample:Lists>
94+
</domain:DemoItem.Content>
95+
</domain:DemoItem>
96+
<domain:DemoItem Name="Trees">
97+
<domain:DemoItem.Content>
98+
<wpfExample:Trees />
99+
</domain:DemoItem.Content>
100+
</domain:DemoItem>
101+
<domain:DemoItem Name="Grids">
102+
<domain:DemoItem.Content>
103+
<wpfExample:Grids>
104+
<wpfExample:Grids.DataContext>
105+
<domain:ListsAndGridsViewModel />
106+
</wpfExample:Grids.DataContext>
107+
</wpfExample:Grids>
108+
</domain:DemoItem.Content>
109+
</domain:DemoItem>
110+
<domain:DemoItem Name="Menus &amp; Tool Bars">
111+
<domain:DemoItem.Content>
112+
<wpfExample:MenusAndToolBars />
113+
</domain:DemoItem.Content>
114+
</domain:DemoItem>
115+
<domain:DemoItem Name="Progress Indicators">
116+
<domain:DemoItem.Content>
117+
<wpfExample:Progress />
118+
</domain:DemoItem.Content>
119+
</domain:DemoItem>
120+
<domain:DemoItem Name="Dialogs">
121+
<domain:DemoItem.Content>
122+
<wpfExample:Dialogs />
123+
</domain:DemoItem.Content>
124+
</domain:DemoItem>
125+
<domain:DemoItem Name="Shadows">
126+
<domain:DemoItem.Content>
127+
<wpfExample:Shadows />
128+
</domain:DemoItem.Content>
129+
</domain:DemoItem>
130+
</ListBox>
131+
<ContentControl Margin="16" Content="{Binding ElementName=DemoItemsListBox, Path=SelectedItem.Content}" />
132+
</DockPanel>
133+
</wpf:DialogHost>
122134
</Window>

0 commit comments

Comments
 (0)