Skip to content

Commit b423ce8

Browse files
committed
2 parents 3487251 + c66dcea commit b423ce8

File tree

8 files changed

+62
-17
lines changed

8 files changed

+62
-17
lines changed

MainDemo.Wpf/Dialogs.xaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@
147147
Grid.Column="3" Margin="8 0 8 0"
148148
>SAMPLE 4: Dialog managed from view model using IsOpen and custom commands (ignoring the provided routed commands).</TextBlock>
149149
<materialDesign:DialogHost Grid.Column="3" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center"
150-
IsOpen="{Binding IsSample4DialogOpen}"
151-
DialogContent="{Binding Sample4Content}">
150+
IsOpen="{Binding IsSample4DialogOpen}"
151+
DialogContent="{Binding Sample4Content}"
152+
CloseOnClickAway="True">
152153
<Border BorderThickness="1" BorderBrush="{DynamicResource PrimaryHueMidBrush}"
153154
MinWidth="256" MinHeight="256" ClipToBounds="True">
154155
<Button HorizontalAlignment="Center" VerticalAlignment="Center"

MainDemo.Wpf/MainWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@
182182
<DockPanel>
183183
<ToggleButton Style="{StaticResource MaterialDesignHamburgerToggleButton}" IsChecked="False"
184184
x:Name="MenuToggleButton"/>
185-
<materialDesign:PopupBox DockPanel.Dock="Right" PlacementMode="BottomAndAlignRightEdges">
185+
<materialDesign:PopupBox DockPanel.Dock="Right" PlacementMode="BottomAndAlignRightEdges" StaysOpen="True">
186186
<StackPanel>
187187
<Button Content="Hello World" Click="MenuPopupButton_OnClick"/>
188188
<Button Content="Nice Popup" Click="MenuPopupButton_OnClick"/>
189-
<Button Content="Goodbye" Click="MenuPopupButton_OnClick"/>
189+
<Button Content="Goodbye" Click="MenuPopupButton_OnClick"/>
190190
</StackPanel>
191191
</materialDesign:PopupBox>
192192
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="22">Material Design In XAML Toolkit</TextBlock>

MaterialDesignThemes.Wpf/DialogHost.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ public enum DialogHostOpenDialogCommandDataContextSource
3636

3737
[TemplatePart(Name = PopupPartName, Type = typeof(Popup))]
3838
[TemplatePart(Name = PopupPartName, Type = typeof(ContentControl))]
39+
[TemplatePart(Name = ContentCoverGridName, Type = typeof(Grid))]
3940
[TemplateVisualState(GroupName = "PopupStates", Name = OpenStateName)]
4041
[TemplateVisualState(GroupName = "PopupStates", Name = ClosedStateName)]
4142
public class DialogHost : ContentControl
4243
{
4344
public const string PopupPartName = "PART_Popup";
4445
public const string PopupContentPartName = "PART_PopupContentElement";
46+
public const string ContentCoverGridName = "PART_ContentCoverGrid";
4547
public const string OpenStateName = "Open";
4648
public const string ClosedStateName = "Closed";
4749

@@ -62,6 +64,7 @@ public class DialogHost : ContentControl
6264

6365
private Popup _popup;
6466
private ContentControl _popupContentControl;
67+
private Grid _contentCoverGrid;
6568
private DialogSession _session;
6669
private DialogOpenedEventHandler _attachedDialogOpenedEventHandler;
6770
private DialogClosingEventHandler _attachedDialogClosingEventHandler;
@@ -330,10 +333,41 @@ public DialogHostOpenDialogCommandDataContextSource OpenDialogCommandDataContext
330333
set { SetValue(OpenDialogCommandDataContextSourceProperty, value); }
331334
}
332335

336+
public static readonly DependencyProperty CloseOnClickAwayProperty = DependencyProperty.Register(
337+
"CloseOnClickAway", typeof (bool), typeof (DialogHost), new PropertyMetadata(default(bool)));
338+
339+
/// <summary>
340+
/// Indicates whether the dialog will close if the user clicks off the dialog, on the obscured background.
341+
/// </summary>
342+
public bool CloseOnClickAway
343+
{
344+
get { return (bool) GetValue(CloseOnClickAwayProperty); }
345+
set { SetValue(CloseOnClickAwayProperty, value); }
346+
}
347+
348+
public static readonly DependencyProperty CloseOnClickAwayParameterProperty = DependencyProperty.Register(
349+
"CloseOnClickAwayParameter", typeof (object), typeof (DialogHost), new PropertyMetadata(default(object)));
350+
351+
/// <summary>
352+
/// Parameter to provide to close handlers if an close due to click away is instigated.
353+
/// </summary>
354+
public object CloseOnClickAwayParameter
355+
{
356+
get { return (object) GetValue(CloseOnClickAwayParameterProperty); }
357+
set { SetValue(CloseOnClickAwayParameterProperty, value); }
358+
}
359+
333360
public override void OnApplyTemplate()
334361
{
362+
if (_contentCoverGrid != null)
363+
_contentCoverGrid.MouseLeftButtonUp -= ContentCoverGridOnMouseLeftButtonUp;
364+
335365
_popup = GetTemplateChild(PopupPartName) as Popup;
336366
_popupContentControl = GetTemplateChild(PopupContentPartName) as ContentControl;
367+
_contentCoverGrid = GetTemplateChild(ContentCoverGridName) as Grid;
368+
369+
if (_contentCoverGrid != null)
370+
_contentCoverGrid.MouseLeftButtonUp += ContentCoverGridOnMouseLeftButtonUp;
337371

338372
VisualStateManager.GoToState(this, SelectState(), false);
339373

@@ -486,6 +520,12 @@ protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
486520
base.OnPreviewMouseDown(e);
487521
}
488522

523+
private void ContentCoverGridOnMouseLeftButtonUp(object sender, MouseButtonEventArgs mouseButtonEventArgs)
524+
{
525+
if (CloseOnClickAway)
526+
Close(CloseOnClickAwayParameter);
527+
}
528+
489529
private void OpenDialogHandler(object sender, ExecutedRoutedEventArgs executedRoutedEventArgs)
490530
{
491531
if (executedRoutedEventArgs.Handled) return;

MaterialDesignThemes.Wpf/PopupBox.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,14 @@ public DataTemplate PopupContentTemplate
214214
set { SetValue(PopupContentTemplateProperty, value); }
215215
}
216216

217+
[Obsolete]
217218
public static readonly DependencyProperty StaysOpenOnEditProperty = DependencyProperty.Register(
218219
nameof(StaysOpenOnEdit), typeof (bool), typeof (PopupBox), new PropertyMetadata(default(bool)));
219220

220221
/// <summary>
221-
/// Indicates if the opup should stay open after a click is made inside the popup.
222+
/// Prefer <see cref="StaysOpen"/>.
222223
/// </summary>
224+
[Obsolete]
223225
public bool StaysOpenOnEdit
224226
{
225227
get { return (bool) GetValue(StaysOpenOnEditProperty); }
@@ -585,7 +587,7 @@ private static void OnLostMouseCapture(object sender, MouseEventArgs e)
585587
if (e.OriginalSource == popupBox)
586588
{
587589
if (Mouse.Captured == null || popupBox._popup == null || !(Mouse.Captured as DependencyObject).IsDescendantOf(popupBox._popup))
588-
{
590+
{
589591
popupBox.Close();
590592
}
591593
}
@@ -601,8 +603,9 @@ private static void OnLostMouseCapture(object sender, MouseEventArgs e)
601603
}
602604
}
603605
else
604-
{
605-
popupBox.Close();
606+
{
607+
if (!popupBox.StaysOpen)
608+
popupBox.Close();
606609
}
607610
}
608611
}

MaterialDesignThemes.Wpf/Themes/Generic.xaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@
478478
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="PART_Popup" Storyboard.TargetProperty="IsOpen">
479479
<DiscreteBooleanKeyFrame Value="True" KeyTime="0" />
480480
</BooleanAnimationUsingKeyFrames>
481-
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="ContentGrid" Storyboard.TargetProperty="Opacity">
481+
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentCoverGrid" Storyboard.TargetProperty="Opacity">
482482
<EasingDoubleKeyFrame Value="0" KeyTime="0" />
483483
<EasingDoubleKeyFrame Value="0.56" KeyTime="0:0:0.3">
484484
<EasingDoubleKeyFrame.EasingFunction>
@@ -518,7 +518,7 @@
518518
<DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0" />
519519
<DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0.3" />
520520
</BooleanAnimationUsingKeyFrames>
521-
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="ContentGrid" Storyboard.TargetProperty="Opacity">
521+
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentCoverGrid" Storyboard.TargetProperty="Opacity">
522522
<EasingDoubleKeyFrame Value="0.56" KeyTime="0" />
523523
<EasingDoubleKeyFrame Value="0" KeyTime="0:0:0.3">
524524
<EasingDoubleKeyFrame.EasingFunction>
@@ -561,7 +561,7 @@
561561
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="PART_Popup" Storyboard.TargetProperty="IsOpen">
562562
<DiscreteBooleanKeyFrame Value="True" KeyTime="0" />
563563
</BooleanAnimationUsingKeyFrames>
564-
<DoubleAnimation Storyboard.TargetName="ContentGrid" Storyboard.TargetProperty="Opacity"
564+
<DoubleAnimation Storyboard.TargetName="PART_ContentCoverGrid" Storyboard.TargetProperty="Opacity"
565565
Duration="0"
566566
To=".56" />
567567
<DoubleAnimation Storyboard.TargetName="PART_PopupContentElement" Storyboard.TargetProperty="Opacity"
@@ -610,6 +610,7 @@
610610
TextOptions.TextRenderingMode="Auto"
611611
Foreground="{DynamicResource MaterialDesignBody}"
612612
FontFamily="{StaticResource MaterialDesignFont}"
613+
Focusable="False"
613614
IsTabStop="False"
614615
Opacity="0"
615616
RenderTransformOrigin=".5,.5"
@@ -631,11 +632,12 @@
631632
x:Name="ContentPresenter" Opacity="1"
632633
Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" />
633634
</AdornerDecorator>
634-
<Grid x:Name="ContentGrid" Background="Black" Opacity="0" IsHitTestVisible="False" Focusable="False" />
635+
<Grid x:Name="PART_ContentCoverGrid" Background="Black" Opacity="0" IsHitTestVisible="False" Focusable="False" />
635636
</Grid>
636637
<ControlTemplate.Triggers>
637638
<Trigger Property="IsOpen" Value="True">
638639
<Setter TargetName="ContentPresenter" Property="IsEnabled" Value="False" />
640+
<Setter TargetName="PART_ContentCoverGrid" Property="IsHitTestVisible" Value="True" />
639641
</Trigger>
640642
</ControlTemplate.Triggers>
641643
</ControlTemplate>

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Card.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
</Grid>
3535
</ControlTemplate>
3636
<Style TargetType="{x:Type wpf:Card}">
37-
<Setter Property="TextOptions.TextFormattingMode" Value="Display" />
3837
<Setter Property="Template" Value="{StaticResource CardTemplate}" />
3938
<Setter Property="Background" Value="{DynamicResource MaterialDesignPaper}" />
4039
<Setter Property="VerticalAlignment" Value="Top" />

MaterialDesignThemes.Wpf/Transitions/CircleWipe.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public void Wipe(TransitionerSlide fromSlide, TransitionerSlide toSlide, Point o
3333
zIndexController.Stack(toSlide, fromSlide);
3434

3535
var zeroKeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero);
36-
var midKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(150));
37-
var endKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300));
36+
var midKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200));
37+
var endKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(400));
3838

3939
var opacityAnimation = new DoubleAnimationUsingKeyFrames();
4040
opacityAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(1, zeroKeyTime));

MaterialDesignThemes.Wpf/Transitions/SlideOutWipe.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public void Wipe(TransitionerSlide fromSlide, TransitionerSlide toSlide, Point o
1616
if (zIndexController == null) throw new ArgumentNullException(nameof(zIndexController));
1717

1818
var zeroKeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero);
19-
var midishKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(100));
20-
var endKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300));
19+
var midishKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(200));
20+
var endKeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(400));
2121

2222
//back out old slide setup
2323
var scaleTransform = new ScaleTransform(1, 1);

0 commit comments

Comments
 (0)