Skip to content

Commit a27c227

Browse files
committed
fix enhancements to dialogs, and more samples
1 parent b97157a commit a27c227

File tree

9 files changed

+369
-127
lines changed

9 files changed

+369
-127
lines changed

MainDemo.Wpf/Dialogs.xaml

Lines changed: 133 additions & 107 deletions
Large diffs are not rendered by default.

MainDemo.Wpf/Domain/DialogsViewModel.cs

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
34
using System.Linq;
5+
using System.Runtime.CompilerServices;
46
using System.Text;
57
using System.Threading.Tasks;
68
using System.Windows.Controls;
79
using System.Windows.Input;
10+
using System.Windows.Threading;
811
using MaterialDesignThemes.Wpf;
912

1013
namespace MaterialDesignColors.WpfExample.Domain
1114
{
12-
public class DialogsViewModel
15+
public class DialogsViewModel : INotifyPropertyChanged
1316
{
17+
public DialogsViewModel()
18+
{
19+
//Sample 4
20+
OpenSample4DialogCommand = new AnotherCommandImplementation(OpenSample4Dialog);
21+
AcceptSample4DialogCommand = new AnotherCommandImplementation(AcceptSample4Dialog);
22+
CancelSample4DialogCommand = new AnotherCommandImplementation(CancelSample4Dialog);
23+
}
24+
25+
#region SAMPLE 3
26+
1427
public ICommand RunDialogCommand => new AnotherCommandImplementation(ExecuteRunDialog);
1528

29+
public ICommand RunExtendedDialogCommand => new AnotherCommandImplementation(ExecuteRunExtendedDialog);
30+
1631
private async void ExecuteRunDialog(object o)
1732
{
1833
//let's set up a little MVVM, cos that's what the cool kids are doing:
@@ -32,5 +47,100 @@ private void ClosingEventHandler(object sender, DialogClosingEventArgs eventArgs
3247
{
3348
Console.WriteLine("You can intercept the closing event, and cancel here.");
3449
}
50+
51+
private async void ExecuteRunExtendedDialog(object o)
52+
{
53+
//let's set up a little MVVM, cos that's what the cool kids are doing:
54+
var view = new SampleDialog
55+
{
56+
DataContext = new object()
57+
};
58+
59+
//show the dialog
60+
var result = await DialogHost.Show(view, "RootDialog", ExtendedClosingEventHandler);
61+
62+
//check the result...
63+
Console.WriteLine("Dialog was closed, the CommandParameter used to close it was: " + (result ?? "NULL"));
64+
}
65+
66+
private void ExtendedClosingEventHandler(object sender, DialogClosingEventArgs eventArgs)
67+
{
68+
if ((bool)eventArgs.Parameter == false) return;
69+
70+
//OK, lets cancel the close...
71+
eventArgs.Cancel();
72+
73+
//...now, lets update the "session" with some new content!
74+
eventArgs.Session.UpdateContent(new SampleProgressDialog());
75+
//note, you can also grab the session when the dialog opens via the DialogOpenedEventHandler
76+
77+
//lets run a fake operation for 3 seconds then close this baby.
78+
Task.Delay(TimeSpan.FromSeconds(3))
79+
.ContinueWith((t, _) => eventArgs.Session.Close(false), null,
80+
TaskScheduler.FromCurrentSynchronizationContext());
81+
}
82+
83+
#endregion
84+
85+
#region SAMPLE 4
86+
87+
//pretty much ignore all the stuff provided, and manage everything via custom commands and a binding for .IsOpen
88+
public ICommand OpenSample4DialogCommand { get; }
89+
public ICommand AcceptSample4DialogCommand { get; }
90+
public ICommand CancelSample4DialogCommand { get; }
91+
92+
private bool _isSample4DialogOpen;
93+
private object _sample4Content;
94+
95+
public bool IsSample4DialogOpen
96+
{
97+
get { return _isSample4DialogOpen; }
98+
set
99+
{
100+
if (_isSample4DialogOpen == value) return;
101+
_isSample4DialogOpen = value;
102+
OnPropertyChanged();
103+
}
104+
}
105+
106+
public object Sample4Content
107+
{
108+
get { return _sample4Content; }
109+
set
110+
{
111+
if (_sample4Content == value) return;
112+
_sample4Content = value;
113+
OnPropertyChanged();
114+
}
115+
}
116+
117+
private void OpenSample4Dialog(object obj)
118+
{
119+
Sample4Content = new Sample4Dialog();
120+
IsSample4DialogOpen = true;
121+
}
122+
123+
private void CancelSample4Dialog(object obj)
124+
{
125+
IsSample4DialogOpen = false;
126+
}
127+
128+
private void AcceptSample4Dialog(object obj)
129+
{
130+
//pretend to do something for 3 seconds, then close
131+
Sample4Content = new SampleProgressDialog();
132+
Task.Delay(TimeSpan.FromSeconds(3))
133+
.ContinueWith((t, _) => IsSample4DialogOpen = false, null,
134+
TaskScheduler.FromCurrentSynchronizationContext());
135+
}
136+
137+
#endregion
138+
139+
public event PropertyChangedEventHandler PropertyChanged;
140+
141+
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
142+
{
143+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
144+
}
35145
}
36146
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<UserControl x:Class="MaterialDesignColors.WpfExample.Domain.Sample4Dialog"
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:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
7+
mc:Ignorable="d" >
8+
<Grid Margin="16">
9+
<Grid.RowDefinitions>
10+
<RowDefinition />
11+
<RowDefinition />
12+
</Grid.RowDefinitions>
13+
<TextBox wpf:TextFieldAssist.Hint="Name" Style="{DynamicResource MaterialDesignFloatingHintTextBox}"
14+
Margin="0 6 0 0"
15+
FontSize="18" Grid.Row="0"
16+
/>
17+
<StackPanel Orientation="Horizontal" Grid.Row="1"
18+
Margin="0 16 0 0">
19+
<Button IsDefault="True" Style="{DynamicResource MaterialDesignFlatButton}"
20+
Command="{Binding AcceptSample4DialogCommand}">
21+
ACCEPT
22+
</Button>
23+
<Button IsCancel="True" Margin="8 0 0 0" Style="{DynamicResource MaterialDesignFlatButton}"
24+
Command="{Binding CancelSample4DialogCommand}">
25+
CANCEL
26+
</Button>
27+
</StackPanel>
28+
</Grid>
29+
</UserControl>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
namespace MaterialDesignColors.WpfExample.Domain
17+
{
18+
/// <summary>
19+
/// Interaction logic for SampleDialog.xaml
20+
/// </summary>
21+
public partial class Sample4Dialog : UserControl
22+
{
23+
public Sample4Dialog()
24+
{
25+
InitializeComponent();
26+
}
27+
}
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<UserControl x:Class="MaterialDesignColors.WpfExample.Domain.SampleProgressDialog"
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+
mc:Ignorable="d">
7+
<ProgressBar Width="24" Height="24" Margin="16"
8+
Style="{DynamicResource MaterialDesignCircularProgressBar}"
9+
IsIndeterminate="True"
10+
Value="33"/>
11+
</UserControl>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
namespace MaterialDesignColors.WpfExample.Domain
17+
{
18+
/// <summary>
19+
/// Interaction logic for SampleProgressDialog.xaml
20+
/// </summary>
21+
public partial class SampleProgressDialog : UserControl
22+
{
23+
public SampleProgressDialog()
24+
{
25+
InitializeComponent();
26+
}
27+
}
28+
}

MainDemo.Wpf/MainDemo.Wpf.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,15 @@
8585
<Compile Include="Domain\DemoItem.cs" />
8686
<Compile Include="Domain\DialogsViewModel.cs" />
8787
<Compile Include="Domain\ListFieldsViewModel.cs" />
88+
<Compile Include="Domain\Sample4Dialog.xaml.cs">
89+
<DependentUpon>Sample4Dialog.xaml</DependentUpon>
90+
</Compile>
8891
<Compile Include="Domain\SampleDialog.xaml.cs">
8992
<DependentUpon>SampleDialog.xaml</DependentUpon>
9093
</Compile>
94+
<Compile Include="Domain\SampleProgressDialog.xaml.cs">
95+
<DependentUpon>SampleProgressDialog.xaml</DependentUpon>
96+
</Compile>
9197
<Compile Include="Domain\SelectableViewModel.cs" />
9298
<Compile Include="Domain\TextFieldsViewModel.cs" />
9399
<Compile Include="Grids.xaml.cs">
@@ -138,10 +144,18 @@
138144
<SubType>Designer</SubType>
139145
<Generator>MSBuild:Compile</Generator>
140146
</Page>
147+
<Page Include="Domain\Sample4Dialog.xaml">
148+
<Generator>MSBuild:Compile</Generator>
149+
<SubType>Designer</SubType>
150+
</Page>
141151
<Page Include="Domain\SampleDialog.xaml">
142152
<SubType>Designer</SubType>
143153
<Generator>MSBuild:Compile</Generator>
144154
</Page>
155+
<Page Include="Domain\SampleProgressDialog.xaml">
156+
<SubType>Designer</SubType>
157+
<Generator>MSBuild:Compile</Generator>
158+
</Page>
145159
<Page Include="Grids.xaml">
146160
<SubType>Designer</SubType>
147161
<Generator>MSBuild:Compile</Generator>

MaterialDesignThemes.Wpf/DialogSession.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,16 @@ internal DialogSession(DialogHost owner)
2020
/// <summary>
2121
/// Gets the <see cref="DialogHost.DialogContent"/> which is currently displayed, so this could be a view model or a UI element.
2222
/// </summary>
23-
/// <exception cref="InvalidOperationException">Thrown if the dialog session has ended.</exception>
24-
public object Content
25-
{
26-
get
27-
{
28-
if (IsDisabled) throw new InvalidOperationException("Dialog session has ended.");
29-
30-
return _owner.DialogContent;
31-
}
32-
}
23+
public object Content => _owner.DialogContent;
3324

3425
/// <summary>
3526
/// Update the currrent content in the dialog.
3627
/// </summary>
3728
/// <param name="content"></param>
38-
/// <exception cref="InvalidOperationException">Thrown if the dialog content is currently set via a binding, or if the dialog session has ended.</exception>
3929
public void UpdateContent(object content)
4030
{
4131
if (content == null) throw new ArgumentNullException(nameof(content));
42-
if (IsDisabled) throw new InvalidOperationException("Dialog session has ended.");
43-
32+
4433
_owner.AssertTargetableContent();
4534
_owner.DialogContent = content;
4635
}
@@ -53,6 +42,7 @@ public void Close()
5342
{
5443
if (IsDisabled) throw new InvalidOperationException("Dialog session has ended.");
5544

45+
_owner.Close(null);
5646
}
5747

5848
/// <summary>
@@ -64,6 +54,7 @@ public void Close(object parameter)
6454
{
6555
if (IsDisabled) throw new InvalidOperationException("Dialog session has ended.");
6656

57+
_owner.Close(parameter);
6758
}
6859
}
6960
}

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ProgressBar.xaml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,25 @@
181181
</Canvas>
182182
</Grid>
183183
<ControlTemplate.Triggers>
184-
<Trigger Property="IsIndeterminate" Value="True">
185-
<Trigger.EnterActions>
184+
<MultiTrigger>
185+
<MultiTrigger.Conditions>
186+
<Condition Property="IsIndeterminate" Value="True" />
187+
<Condition Property="IsVisible" Value="True" />
188+
</MultiTrigger.Conditions>
189+
<MultiTrigger.EnterActions>
186190
<RemoveStoryboard BeginStoryboardName="IsFullyIndeterminateStoryboard" />
187191
<BeginStoryboard Storyboard="{StaticResource IsIndeterminateStoryboard}"
188192
Name="IsIndeterminateStoryboard"/>
189-
</Trigger.EnterActions>
190-
<Trigger.ExitActions>
193+
</MultiTrigger.EnterActions>
194+
<MultiTrigger.ExitActions>
191195
<RemoveStoryboard BeginStoryboardName="IsIndeterminateStoryboard" />
192-
</Trigger.ExitActions>
193-
</Trigger>
196+
</MultiTrigger.ExitActions>
197+
</MultiTrigger>
194198
<MultiTrigger>
195199
<MultiTrigger.Conditions>
196200
<Condition Property="IsIndeterminate" Value="True" />
197201
<Condition Property="Value" Value="0" />
202+
<Condition Property="IsVisible" Value="True" />
198203
</MultiTrigger.Conditions>
199204
<MultiTrigger.EnterActions>
200205
<RemoveStoryboard BeginStoryboardName="IsIndeterminateStoryboard" />

0 commit comments

Comments
 (0)