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 155155 </ComboBox >
156156
157157 <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} " >
160160 <Button .Style>
161161 <Style TargetType =" Button" BasedOn =" {StaticResource MaterialDesignPopupBoxButton}" >
162162 <Setter Property =" Foreground" Value =" Red" />
Original file line number Diff line number Diff line change @@ -103,6 +103,12 @@ public class PopupBox : ContentControl
103103 public const string PopupContentControlPartName = "PART_PopupContentControl" ;
104104 public const string PopupIsOpenStateName = "IsOpen" ;
105105 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+
106112 private PopupEx _popup ;
107113 private ContentControl _popupContentControl ;
108114 private ToggleButton _toggleButton ;
@@ -394,7 +400,9 @@ public override void OnApplyTemplate()
394400 _popup = GetTemplateChild ( PopupPartName ) as PopupEx ;
395401 _popupContentControl = GetTemplateChild ( PopupContentControlPartName ) as ContentControl ;
396402 _toggleButton = GetTemplateChild ( TogglePartName ) as ToggleButton ;
397-
403+
404+ _popup ? . CommandBindings . Add ( new CommandBinding ( ClosePopupCommand , ClosePopupHandler ) ) ;
405+
398406 if ( _toggleButton != null )
399407 _toggleButton . PreviewMouseLeftButtonUp += ToggleButtonOnPreviewMouseLeftButtonUp ;
400408
@@ -440,6 +448,11 @@ protected override void OnMouseEnter(MouseEventArgs e)
440448 base . OnMouseEnter ( e ) ;
441449 }
442450
451+ private void ClosePopupHandler ( object sender , ExecutedRoutedEventArgs executedRoutedEventArgs )
452+ {
453+ IsPopupOpen = false ;
454+ }
455+
443456 private void OnLayoutUpdated ( object sender , EventArgs eventArgs )
444457 {
445458 if ( _popupContentControl != null && _popup != null &&
You can’t perform that action at this time.
0 commit comments