Skip to content

Commit 7c5c509

Browse files
committed
Dialogz. v0.1
1 parent 7838d8e commit 7c5c509

13 files changed

+559
-103
lines changed

MainDemo.Wpf/Dialogs.xaml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<UserControl x:Class="MaterialDesignColors.WpfExample.Dialogs"
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:MaterialDesignColors.WpfExample"
7+
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
8+
xmlns:system="clr-namespace:System;assembly=mscorlib"
9+
mc:Ignorable="d"
10+
d:DesignHeight="300" d:DesignWidth="300">
11+
<UserControl.Resources>
12+
<ResourceDictionary>
13+
<ResourceDictionary.MergedDictionaries>
14+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml" />
15+
</ResourceDictionary.MergedDictionaries>
16+
</ResourceDictionary>
17+
</UserControl.Resources>
18+
<Grid>
19+
<Grid.RowDefinitions>
20+
<RowDefinition Height="Auto" />
21+
<RowDefinition Height="*" />
22+
</Grid.RowDefinitions>
23+
<StackPanel>
24+
<TextBlock>WORK IN PROGRESS...DO NOT USE YET...API NOT FINALISED.</TextBlock>
25+
<!--
26+
<TextBlock>Dialogs can be hosted at any level of you visual tree.</TextBlock>
27+
<TextBlock>When a dialog is open the underlying content will be disabled.</TextBlock>
28+
-->
29+
</StackPanel>
30+
31+
<Grid Grid.Row="1">
32+
<Grid.RowDefinitions>
33+
<RowDefinition Height="Auto" />
34+
<RowDefinition Height="*" />
35+
</Grid.RowDefinitions>
36+
<Grid.ColumnDefinitions>
37+
<ColumnDefinition Width="1*" />
38+
<ColumnDefinition Width="1*" />
39+
</Grid.ColumnDefinitions>
40+
41+
<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"
44+
Grid.Column="0" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center">
45+
<wpf:DialogHost.DialogContent>
46+
<StackPanel Margin="16">
47+
<TextBlock>Add a new fruit.</TextBlock>
48+
<TextBox Margin="0 8 0 0" HorizontalAlignment="Stretch" x:Name="FruitTextBox" />
49+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" >
50+
<Button Style="{StaticResource MaterialDesignFlatButton}"
51+
IsDefault="True"
52+
Margin="0 8 8 0"
53+
Command="wpf:DialogHost.CloseDialogCommand">
54+
<Button.CommandParameter>
55+
<system:Boolean>True</system:Boolean>
56+
</Button.CommandParameter>
57+
ACCEPT
58+
</Button>
59+
<Button Style="{StaticResource MaterialDesignFlatButton}"
60+
IsCancel="True"
61+
Margin="0 8 8 0"
62+
Command="wpf:DialogHost.CloseDialogCommand">
63+
<Button.CommandParameter>
64+
<system:Boolean>False</system:Boolean>
65+
</Button.CommandParameter>
66+
CANCEL
67+
</Button>
68+
</StackPanel>
69+
</StackPanel>
70+
</wpf:DialogHost.DialogContent>
71+
<Border BorderThickness="1" BorderBrush="{DynamicResource PrimaryHueMidBrush}"
72+
MinWidth="256" MinHeight="256">
73+
<Grid>
74+
<Grid.RowDefinitions>
75+
<RowDefinition Height="*" />
76+
<RowDefinition Height="Auto" />
77+
</Grid.RowDefinitions>
78+
<ListBox x:Name="FruitListBox">
79+
<ListBoxItem>Apple</ListBoxItem>
80+
<ListBoxItem>Banana</ListBoxItem>
81+
<ListBoxItem>Pear</ListBoxItem>
82+
</ListBox>
83+
<wpf:ColorZone Mode="PrimaryMid" Grid.Row="1">
84+
<TextBlock Margin="16">Fruit Bowl</TextBlock>
85+
</wpf:ColorZone>
86+
<Button Style="{StaticResource MaterialDesignFloatingActionAccentButton}"
87+
Command="{x:Static wpf:DialogHost.OpenDialogCommand}"
88+
VerticalAlignment="Bottom" HorizontalAlignment="Right"
89+
Grid.Row="0" Margin="0 0 28 -20">
90+
<Viewbox Width="22" Height="22">
91+
<Canvas Width="24" Height="24">
92+
<Path Data="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z" Fill="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Foreground}" />
93+
</Canvas>
94+
</Viewbox>
95+
</Button>
96+
</Grid>
97+
</Border>
98+
</wpf:DialogHost>
99+
</Grid>
100+
</Grid>
101+
</UserControl>

MainDemo.Wpf/Dialogs.xaml.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
using MaterialDesignThemes.Wpf;
16+
17+
namespace MaterialDesignColors.WpfExample
18+
{
19+
/// <summary>
20+
/// Interaction logic for Dialogs.xaml
21+
/// </summary>
22+
public partial class Dialogs : UserControl
23+
{
24+
public Dialogs()
25+
{
26+
InitializeComponent();
27+
}
28+
29+
private void DialogHost_OnDialogClosing(object sender, DialogClosingEventArgs eventArgs)
30+
{
31+
Console.WriteLine("Closing dialog with parameter: " + (eventArgs.Parameter ?? ""));
32+
33+
//you can cancel the dialog close:
34+
//eventArgs.Cancel();
35+
36+
if (!Equals(eventArgs.Parameter, true)) return;
37+
38+
if (!string.IsNullOrWhiteSpace(FruitTextBox.Text))
39+
FruitListBox.Items.Add(FruitTextBox.Text.Trim());
40+
}
41+
}
42+
}

MainDemo.Wpf/MainDemo.Wpf.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
<Compile Include="ColorZones.xaml.cs">
7979
<DependentUpon>ColorZones.xaml</DependentUpon>
8080
</Compile>
81+
<Compile Include="Dialogs.xaml.cs">
82+
<DependentUpon>Dialogs.xaml</DependentUpon>
83+
</Compile>
8184
<Compile Include="Domain\AnotherCommandImplementation.cs" />
8285
<Compile Include="Domain\DemoItem.cs" />
8386
<Compile Include="Domain\ListFieldsViewModel.cs" />
@@ -124,6 +127,10 @@
124127
<SubType>Designer</SubType>
125128
<Generator>MSBuild:Compile</Generator>
126129
</Page>
130+
<Page Include="Dialogs.xaml">
131+
<SubType>Designer</SubType>
132+
<Generator>MSBuild:Compile</Generator>
133+
</Page>
127134
<Page Include="Grids.xaml">
128135
<SubType>Designer</SubType>
129136
<Generator>MSBuild:Compile</Generator>

MainDemo.Wpf/MainWindow.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@
105105
<wpfExample:Progress />
106106
</domain:DemoItem.Content>
107107
</domain:DemoItem>
108+
<domain:DemoItem Name="Dialogs">
109+
<domain:DemoItem.Content>
110+
<wpfExample:Dialogs />
111+
</domain:DemoItem.Content>
112+
</domain:DemoItem>
108113
</ListBox>
109114
<ContentControl Margin="16" Content="{Binding ElementName=DemoItemsListBox, Path=SelectedItem.Content}" />
110115
</DockPanel>

MaterialDesignThemes.Wpf/ColorZone.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public enum ColorZoneMode
2222
PrimaryLight,
2323
PrimaryMid,
2424
PrimaryDark,
25-
Accent
25+
Accent,
26+
Light,
27+
Dark
2628
}
2729

2830
/// <summary>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Windows;
2+
3+
namespace MaterialDesignThemes.Wpf
4+
{
5+
public class DialogClosingEventArgs : RoutedEventArgs
6+
{
7+
public DialogClosingEventArgs(object parameter)
8+
{
9+
Parameter = parameter;
10+
}
11+
12+
public DialogClosingEventArgs(object parameter, RoutedEvent routedEvent) : base(routedEvent)
13+
{
14+
Parameter = parameter;
15+
}
16+
17+
public DialogClosingEventArgs(object parameter, RoutedEvent routedEvent, object source) : base(routedEvent, source)
18+
{
19+
Parameter = parameter;
20+
}
21+
22+
public void Cancel()
23+
{
24+
IsCancelled = true;
25+
}
26+
27+
public bool IsCancelled { get; private set; }
28+
29+
/// <summary>
30+
/// Gets the paramter originally provided to <see cref="DialogHost.CloseDialogCommand"/>/
31+
/// </summary>
32+
public object Parameter { get; }
33+
}
34+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace MaterialDesignThemes.Wpf
2+
{
3+
public delegate void DialogClosingEventHandler(object sender, DialogClosingEventArgs eventArgs);
4+
}

0 commit comments

Comments
 (0)