Skip to content

Commit 13923ca

Browse files
committed
floating action button - additional toggle command
1 parent c52119e commit 13923ca

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

MainDemo.Wpf/Buttons.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:system="clr-namespace:System;assembly=mscorlib"
77
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
8+
xmlns:wpfExample="clr-namespace:MaterialDesignColors.WpfExample"
89
mc:Ignorable="d"
910
d:DesignHeight="300" d:DesignWidth="300">
1011
<UserControl.Resources>
@@ -122,6 +123,8 @@
122123
<materialDesign:PopupBox Style="{StaticResource MaterialDesignMultiFloatingActionAccentPopupBox}"
123124
PlacementMode="BottomAndAlignCentres"
124125
HorizontalAlignment="Right"
126+
ToggleCheckedContentCommand="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=wpfExample:Buttons}, Path=FloatingActionDemoCommand}"
127+
ToggleCheckedContentCommandParameter="wowsers"
125128
Margin="0 0 48 0"
126129
ToolTip="PopupBox, Style MaterialDesignMultiFloatingActionAccentPopupBox">
127130
<materialDesign:PopupBox.ToggleCheckedContent>

MainDemo.Wpf/Buttons.xaml.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Windows.Media.Imaging;
1313
using System.Windows.Navigation;
1414
using System.Windows.Shapes;
15+
using MaterialDesignColors.WpfExample.Domain;
1516

1617
namespace MaterialDesignColors.WpfExample
1718
{
@@ -20,12 +21,26 @@ namespace MaterialDesignColors.WpfExample
2021
/// </summary>
2122
public partial class Buttons : UserControl
2223
{
24+
private readonly ICommand _floatingActionDemoCommand;
25+
2326
public Buttons()
2427
{
25-
InitializeComponent();
28+
InitializeComponent();
29+
30+
_floatingActionDemoCommand = new AnotherCommandImplementation(Execute);
31+
}
32+
33+
public ICommand FloatingActionDemoCommand
34+
{
35+
get { return _floatingActionDemoCommand; }
36+
}
37+
38+
private void Execute(object o)
39+
{
40+
Console.WriteLine("Floating action button command. - " + (o ?? "NULL").ToString());
2641
}
2742

28-
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
43+
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
2944
{
3045
System.Diagnostics.Debug.WriteLine("Just checking we haven't suppressed the button.");
3146
}

MaterialDesignThemes.Wpf/PopupBox.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,30 @@ public DataTemplate ToggleCheckedContentTemplate
141141
set { SetValue(ToggleCheckedContentTemplateProperty, value); }
142142
}
143143

144+
public static readonly DependencyProperty ToggleCheckedContentCommandProperty = DependencyProperty.Register(
145+
"ToggleCheckedContentCommand", typeof (ICommand), typeof (PopupBox), new PropertyMetadata(default(ICommand)));
146+
147+
/// <summary>
148+
/// Command to execute if toggle is checked (popup is open) and <see cref="ToggleCheckedContent"/> is set.
149+
/// </summary>
150+
public ICommand ToggleCheckedContentCommand
151+
{
152+
get { return (ICommand) GetValue(ToggleCheckedContentCommandProperty); }
153+
set { SetValue(ToggleCheckedContentCommandProperty, value); }
154+
}
155+
156+
public static readonly DependencyProperty ToggleCheckedContentCommandParameterProperty = DependencyProperty.Register(
157+
"ToggleCheckedContentCommandParameter", typeof (object), typeof (PopupBox), new PropertyMetadata(default(object)));
158+
159+
/// <summary>
160+
/// Command parameter to use in conjunction with <see cref="ToggleCheckedContentCommand"/>.
161+
/// </summary>
162+
public object ToggleCheckedContentCommandParameter
163+
{
164+
get { return (object) GetValue(ToggleCheckedContentCommandParameterProperty); }
165+
set { SetValue(ToggleCheckedContentCommandParameterProperty, value); }
166+
}
167+
144168
public static readonly DependencyProperty PopupContentProperty = DependencyProperty.Register(
145169
"PopupContent", typeof (object), typeof (PopupBox), new PropertyMetadata(default(object)));
146170

@@ -470,6 +494,14 @@ private void ToggleButtonOnPreviewMouseLeftButtonUp(object sender, MouseButtonEv
470494
{
471495
if (PopupMode == PopupBoxPopupMode.Click || !IsPopupOpen) return;
472496

497+
if (ToggleCheckedContent != null
498+
&& ToggleCheckedContentCommand != null
499+
&& ToggleCheckedContentCommand.CanExecute(ToggleCheckedContentCommandParameter)
500+
)
501+
{
502+
ToggleCheckedContentCommand.Execute(ToggleCheckedContentCommandParameter);
503+
}
504+
473505
Close();
474506
Mouse.Capture(null);
475507
mouseButtonEventArgs.Handled = true;

0 commit comments

Comments
 (0)