add ButtonStyle prop to PopupControl

This commit is contained in:
John Colvin committed 2019-10-26 16:26:34 -05:00
1 parent c66dfa85c1
commit a6f9fbaa3c
1 file changed
+22 -9
@@ -10,9 +10,18 @@ namespace mbts.ui.controls {
/// Interaction logic for PopupControl.xaml
/// </summary>
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<Style, PopupControl>(
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;