private static void OnMouseButtonDown(object sender, MouseButtonEventArgs args) { SplitButton splitButton = sender as SplitButton; //if (!splitButton.IsKeyboardFocusWithin) //{ // splitButton.Focus(); // return; //} if (Mouse.Captured == splitButton && args.OriginalSource == splitButton) { splitButton.CloseSubmenu(); return; } if (args.Source is MenuItem) { MenuItem menuItem = (MenuItem)args.Source; if (!menuItem.HasItems) { splitButton.CloseSubmenu(); menuItem.RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent, menuItem)); } } }
private static void OnPreviewKeyDown(object sender, KeyEventArgs args) { if (openSplitButton != null) { if (args.Key == Key.Escape || args.Key == Key.System) { openSplitButton.CloseSubmenu(); args.Handled = true; } } }