From a6f9fbaa3cd58ca87b8620cb4437c1af61572eaf Mon Sep 17 00:00:00 2001 From: John Colvin Date: Sat, 12 Oct 2019 22:14:46 -0500 Subject: [PATCH] add ButtonStyle prop to PopupControl --- .../view/Controls/Popup/PopupControl.xaml.cs | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/client/spark/view/Controls/Popup/PopupControl.xaml.cs b/src/client/spark/view/Controls/Popup/PopupControl.xaml.cs index b8b07bddb..6301869a0 100644 --- a/src/client/spark/view/Controls/Popup/PopupControl.xaml.cs +++ b/src/client/spark/view/Controls/Popup/PopupControl.xaml.cs @@ -10,9 +10,18 @@ namespace mbts.ui.controls { /// Interaction logic for PopupControl.xaml /// public class PopupControl : HeaderedContentControl { + IDisposable _popup_hook; + Popup _popup; + Button _button; + static PopupControl() => DefaultStyleKeyProperty.OverrideMetadata(typeof(PopupControl), new FrameworkPropertyMetadata(typeof(PopupControl))); + public PopupControl() { + CommandBindings.Add(new CommandBinding(OpenCommand, (s, e) => IsOpen = true)); + CommandBindings.Add(new CommandBinding(CloseCommand, (s, e) => IsOpen = false)); + } + public static readonly RoutedCommand OpenCommand = new RoutedCommand("Open", typeof(PopupControl)), CloseCommand = new RoutedCommand("Close", typeof(PopupControl)); @@ -23,6 +32,16 @@ namespace mbts.ui.controls { public event RoutedEventHandler Opened { add => AddHandler(OpenedEvent, value); remove => RemoveHandler(OpenedEvent, value); } public event RoutedEventHandler Closed { add => AddHandler(ClosedEvent, value); remove => RemoveHandler(ClosedEvent, value); } + public static readonly DependencyProperty ButtonStyleProperty = + WPFHelper.create_dp( + nameof(ButtonStyle), + (o, v) => WPFHelper.apply_style(ref o._button, v)); + + public Style ButtonStyle { + get => GetValue(ButtonStyleProperty) as Style; + set => SetValue(ButtonStyleProperty, value); + } + #region PopupPlacement public static readonly DependencyProperty PopupPlacementProperty = DependencyProperty.Register("PopupPlacement", typeof(PlacementMode), typeof(PopupControl), new PropertyMetadata(PlacementMode.Right, OnPopupPlacementChanged)); private static void OnPopupPlacementChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { d.SetValue(IsOpenTransformPropertyKey, _get_is_open_transform((PlacementMode)e.NewValue)); } @@ -105,18 +124,12 @@ namespace mbts.ui.controls { } #endregion - public PopupControl() { - CommandBindings.Add(new CommandBinding(OpenCommand, (s, e) => IsOpen = true)); - CommandBindings.Add(new CommandBinding(CloseCommand, (s, e) => IsOpen = false)); - } - - IDisposable _popup_hook; - Popup _popup; - Button _button; - public override void OnApplyTemplate() { Disposable.dispose(ref _popup_hook); + // button _button = (Button)GetTemplateChild("button"); + WPFHelper.apply_style(ref _button, ButtonStyle); + // popup _popup = (Popup)GetTemplateChild("popup"); _popup.HorizontalOffset = HorizontalOffset; _popup.VerticalOffset = VerticalOffset;