Skip to content

Commit 9c8d873

Browse files
committed
floating action polish
1 parent ab1c0e5 commit 9c8d873

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

MainDemo.Wpf/Buttons.xaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml" />
1414
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.CheckBox.xaml" />
1515
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ListBox.xaml" />
16+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.PopupBox.xaml" />
1617
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.RadioButton.xaml" />
1718
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToggleButton.xaml" />
1819
</ResourceDictionary.MergedDictionaries>
@@ -106,6 +107,16 @@
106107
</Canvas>
107108
</Viewbox>
108109
</Button>
110+
<materialDesign:PopupBox Style="{StaticResource MaterialDesignMultiFloatingActionPopupBox}"
111+
PlacementMode="BottomAndAlignCentres"
112+
ToolTipService.Placement="Right"
113+
ToolTip="PopupBox, Style MaterialDesignMultiFloatingActionPopupBox">
114+
<StackPanel>
115+
<Button ToolTip="One">1</Button>
116+
<Button ToolTip="Two">2</Button>
117+
<Button ToolTip="Three">3</Button>
118+
</StackPanel>
119+
</materialDesign:PopupBox>
109120
</StackPanel>
110121
<StackPanel Grid.Row="2" Orientation="Horizontal" Margin="0 16 0 0">
111122
<Button Style="{StaticResource MaterialDesignRaisedLightButton}" Margin="0 0 8 0" Width="100"

MaterialDesignThemes.Wpf/PopupBox.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public enum PopupBoxPopupMode
7070
/// </summary>
7171
[TemplatePart(Name = PopupPartName, Type = typeof(Popup))]
7272
[TemplatePart(Name = PopupContentControlPartName, Type = typeof(ContentControl))]
73+
[TemplatePart(Name = TogglePartName, Type = typeof(ToggleButton))]
7374
[TemplateVisualState(GroupName = "PopupStates", Name = PopupIsOpenStateName)]
7475
[TemplateVisualState(GroupName = "PopupStates", Name = PopupIsClosedStateName)]
7576
[ContentProperty("PopupContent")]
@@ -82,6 +83,7 @@ public class PopupBox : ContentControl
8283
public const string PopupIsClosedStateName = "IsClosed";
8384
private PopupEx _popup;
8485
private ContentControl _popupContentControl;
86+
private ToggleButton _toggleButton;
8587

8688
static PopupBox()
8789
{
@@ -166,10 +168,8 @@ private static void IsPopupOpenPropertyChangedCallback(DependencyObject dependen
166168
Mouse.Capture(null);
167169
}
168170

169-
if (newValue)
170-
{
171-
popupBox.AnimateChildren();
172-
}
171+
if (newValue)
172+
popupBox.AnimateChildren();
173173

174174
VisualStateManager.GoToState(popupBox, newValue ? PopupIsOpenStateName : PopupIsClosedStateName, true);
175175
}
@@ -228,14 +228,19 @@ public override void OnApplyTemplate()
228228
{
229229
if (_popup != null)
230230
_popup.Loaded -= PopupOnLoaded;
231+
if (_toggleButton != null)
232+
_toggleButton.PreviewMouseLeftButtonUp -= ToggleButtonOnPreviewMouseLeftButtonUp;
231233

232234
base.OnApplyTemplate();
233235

234236
_popup = GetTemplateChild(PopupPartName) as PopupEx;
235237
_popupContentControl = GetTemplateChild(PopupContentControlPartName) as ContentControl;
238+
_toggleButton = GetTemplateChild(TogglePartName) as ToggleButton;
236239

237240
if (_popup != null)
238241
_popup.Loaded += PopupOnLoaded;
242+
if (_toggleButton != null)
243+
_toggleButton.PreviewMouseLeftButtonUp += ToggleButtonOnPreviewMouseLeftButtonUp;
239244

240245
VisualStateManager.GoToState(this, IsPopupOpen ? PopupIsOpenStateName : PopupIsClosedStateName, false);
241246
}
@@ -254,12 +259,12 @@ protected override void OnMouseEnter(MouseEventArgs e)
254259
{
255260
if (PopupMode == PopupBoxPopupMode.MouseOverEager
256261
|| PopupMode == PopupBoxPopupMode.MouseOver)
257-
262+
258263
SetCurrentValue(IsPopupOpenProperty, true);
259264

260265
base.OnMouseEnter(e);
261266
}
262-
267+
263268
protected override void OnMouseLeave(MouseEventArgs e)
264269
{
265270
if (PopupMode == PopupBoxPopupMode.MouseOverEager
@@ -419,7 +424,7 @@ private static void OnMouseButtonDown(object sender, MouseButtonEventArgs e)
419424
}
420425

421426
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
422-
{
427+
{
423428
if (IsPopupOpen && !StaysOpen)
424429
{
425430
Close();
@@ -437,6 +442,15 @@ private void PopupOnLoaded(object sender, RoutedEventArgs routedEventArgs)
437442
_popup.IsOpen = true;
438443
}
439444

445+
private void ToggleButtonOnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs mouseButtonEventArgs)
446+
{
447+
if (PopupMode == PopupBoxPopupMode.Click || !IsPopupOpen) return;
448+
449+
Close();
450+
Mouse.Capture(null);
451+
mouseButtonEventArgs.Handled = true;
452+
}
453+
440454
private static object CoerceToolTipIsEnabled(DependencyObject dependencyObject, object value)
441455
{
442456
var popupBox = (PopupBox) dependencyObject;

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.PopupBox.xaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
<Setter.Value>
8282
<ControlTemplate TargetType="{x:Type wpf:PopupBox}">
8383
<ControlTemplate.Resources>
84+
<Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource MaterialDesignToolTip}">
85+
<Style.Setters>
86+
<Setter Property="Margin" Value="8 10 8 10" />
87+
</Style.Setters>
88+
</Style>
8489
<Style TargetType="ToggleButton" x:Key="ToggleButtonStyle">
8590
<Setter Property="Template">
8691
<Setter.Value>
@@ -254,7 +259,8 @@
254259
<Setter.Value>
255260
<Viewbox Width="24" Height="24">
256261
<Canvas Width="24" Height="24">
257-
<Path Data="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z" Fill="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=wpf:PopupBox}, Path=Foreground}" />
262+
<Path Data="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z"
263+
Fill="{DynamicResource PrimaryHueMidForegroundBrush}" />
258264
</Canvas>
259265
</Viewbox>
260266
</Setter.Value>

0 commit comments

Comments
 (0)