File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 155
155
</ComboBox >
156
156
157
157
<StackPanel Grid.Row=" 5" Grid.ColumnSpan=" 2" Orientation =" Horizontal" HorizontalAlignment =" Right" >
158
- <Button Content =" _Save" />
159
- <Button Content =" _Cancel" >
158
+ <Button Content =" _Save" Command = " {x:Static materialDesign:PopupBox.ClosePopupCommand} " />
159
+ <Button Content =" _Cancel" Command = " {x:Static materialDesign:PopupBox.ClosePopupCommand} " >
160
160
<Button .Style>
161
161
<Style TargetType =" Button" BasedOn =" {StaticResource MaterialDesignPopupBoxButton}" >
162
162
<Setter Property =" Foreground" Value =" Red" />
Original file line number Diff line number Diff line change @@ -103,6 +103,12 @@ public class PopupBox : ContentControl
103
103
public const string PopupContentControlPartName = "PART_PopupContentControl" ;
104
104
public const string PopupIsOpenStateName = "IsOpen" ;
105
105
public const string PopupIsClosedStateName = "IsClosed" ;
106
+
107
+ /// <summary>
108
+ /// Routed command to be used inside of a popup content to close it.
109
+ /// </summary>
110
+ public static RoutedCommand ClosePopupCommand = new RoutedCommand ( ) ;
111
+
106
112
private PopupEx _popup ;
107
113
private ContentControl _popupContentControl ;
108
114
private ToggleButton _toggleButton ;
@@ -394,7 +400,9 @@ public override void OnApplyTemplate()
394
400
_popup = GetTemplateChild ( PopupPartName ) as PopupEx ;
395
401
_popupContentControl = GetTemplateChild ( PopupContentControlPartName ) as ContentControl ;
396
402
_toggleButton = GetTemplateChild ( TogglePartName ) as ToggleButton ;
397
-
403
+
404
+ _popup ? . CommandBindings . Add ( new CommandBinding ( ClosePopupCommand , ClosePopupHandler ) ) ;
405
+
398
406
if ( _toggleButton != null )
399
407
_toggleButton . PreviewMouseLeftButtonUp += ToggleButtonOnPreviewMouseLeftButtonUp ;
400
408
@@ -440,6 +448,11 @@ protected override void OnMouseEnter(MouseEventArgs e)
440
448
base . OnMouseEnter ( e ) ;
441
449
}
442
450
451
+ private void ClosePopupHandler ( object sender , ExecutedRoutedEventArgs executedRoutedEventArgs )
452
+ {
453
+ IsPopupOpen = false ;
454
+ }
455
+
443
456
private void OnLayoutUpdated ( object sender , EventArgs eventArgs )
444
457
{
445
458
if ( _popupContentControl != null && _popup != null &&
You can’t perform that action at this time.
0 commit comments