/// <summary> /// Set the IsSubmenuOpen property value at the right time. /// </summary> private static Object CoerceIsSubmenuOpen(DependencyObject element, Object value) { SplitButton splitButton = element as SplitButton; if ((Boolean)value) { if (!splitButton.IsLoaded) { splitButton.Loaded += delegate(Object sender, RoutedEventArgs e) { splitButton.CoerceValue(IsSubmenuOpenProperty); }; return(BooleanBoxes.FalseBox); } } return((Boolean)value && splitButton.HasItems); }
private static void OnMenuItemClick(Object sender, RoutedEventArgs e) { SplitButton splitButton = sender as SplitButton; MenuItem menuItem = e.OriginalSource as MenuItem; // To make the ButtonClickEvent get fired as we expected, you should mark the ClickEvent // as handled to prevent the event from poping up to the button portion of the SplitButton. if (menuItem != null && !typeof(MenuItem).IsAssignableFrom(menuItem.Parent.GetType())) { e.Handled = true; } if (menuItem != null && splitButton != null) { if (splitButton.IsSubmenuOpen) { splitButton.CloseSubmenu(); } } }
private static void OnIsSubmenuOpenChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { SplitButton splitButton = sender as SplitButton; if ((Boolean)e.NewValue) { if (Mouse.Captured != splitButton) { Mouse.Capture(splitButton, CaptureMode.SubTree); } } else { if (Mouse.Captured == splitButton) { Mouse.Capture(null); } if (splitButton.IsKeyboardFocused) { splitButton.Focus(); } } }