Skip to content

Commit 0f8de61

Browse files
committed
command for popup box toggle click
1 parent e6cc21c commit 0f8de61

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

MainDemo.Wpf/Buttons.xaml.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,14 @@ namespace MaterialDesignColors.WpfExample
2121
/// </summary>
2222
public partial class Buttons : UserControl
2323
{
24-
private readonly ICommand _floatingActionDemoCommand;
25-
2624
public Buttons()
2725
{
2826
InitializeComponent();
2927

30-
_floatingActionDemoCommand = new AnotherCommandImplementation(Execute);
28+
FloatingActionDemoCommand = new AnotherCommandImplementation(Execute);
3129
}
3230

33-
public ICommand FloatingActionDemoCommand
34-
{
35-
get { return _floatingActionDemoCommand; }
36-
}
31+
public ICommand FloatingActionDemoCommand { get; }
3732

3833
private void Execute(object o)
3934
{
@@ -42,7 +37,7 @@ private void Execute(object o)
4237

4338
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
4439
{
45-
System.Diagnostics.Debug.WriteLine("Just checking we haven't suppressed the button.");
40+
Console.WriteLine("Just checking we haven't suppressed the button.");
4641
}
4742
}
4843
}

MaterialDesignThemes.Wpf/PopupBox.cs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Diagnostics;
34
using System.Linq;
45
using System.Runtime.InteropServices;
@@ -272,6 +273,27 @@ public PopupBoxPopupMode PopupMode
272273
/// </summary>
273274
public CustomPopupPlacementCallback PopupPlacementMethod => GetPopupPlacement;
274275

276+
/// <summary>
277+
/// Event raised when the checked toggled content (if set) is clicked.
278+
/// </summary>
279+
public static readonly RoutedEvent ToggleCheckedContentClickEvent = EventManager.RegisterRoutedEvent("ToggleCheckedContentClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(PopupBox));
280+
281+
/// <summary>
282+
/// Event raised when the checked toggled content (if set) is clicked.
283+
/// </summary>
284+
[Category("Behavior")]
285+
public event RoutedEventHandler ToggleCheckedContentClick { add { AddHandler(ToggleCheckedContentClickEvent, value); } remove { RemoveHandler(ToggleCheckedContentClickEvent, value); } }
286+
287+
288+
/// <summary>
289+
/// Raises <see cref="ToggleCheckedContentClickEvent"/>.
290+
/// </summary>
291+
protected virtual void OnToggleCheckedContentClick()
292+
{
293+
var newEvent = new RoutedEventArgs(ToggleCheckedContentClickEvent, this);
294+
RaiseEvent(newEvent);
295+
}
296+
275297
public override void OnApplyTemplate()
276298
{
277299
if (_popup != null)
@@ -495,12 +517,16 @@ private void ToggleButtonOnPreviewMouseLeftButtonUp(object sender, MouseButtonEv
495517
{
496518
if (PopupMode == PopupBoxPopupMode.Click || !IsPopupOpen) return;
497519

498-
if (ToggleCheckedContent != null
499-
&& ToggleCheckedContentCommand != null
500-
&& ToggleCheckedContentCommand.CanExecute(ToggleCheckedContentCommandParameter)
501-
)
520+
if (ToggleCheckedContent != null)
502521
{
503-
ToggleCheckedContentCommand.Execute(ToggleCheckedContentCommandParameter);
522+
OnToggleCheckedContentClick();
523+
524+
if (ToggleCheckedContentCommand != null
525+
&& ToggleCheckedContentCommand.CanExecute(ToggleCheckedContentCommandParameter)
526+
)
527+
{
528+
ToggleCheckedContentCommand.Execute(ToggleCheckedContentCommandParameter);
529+
}
504530
}
505531

506532
Close();

0 commit comments

Comments
 (0)