diff --git a/MainDemo.Wpf/Toggles.xaml b/MainDemo.Wpf/Toggles.xaml index b26b34ca70..4274673cca 100644 --- a/MainDemo.Wpf/Toggles.xaml +++ b/MainDemo.Wpf/Toggles.xaml @@ -338,11 +338,11 @@ - + - + diff --git a/MaterialDesign3.Demo.Wpf/Toggles.xaml b/MaterialDesign3.Demo.Wpf/Toggles.xaml index 3e2d6a38be..ecaa4e7c77 100644 --- a/MaterialDesign3.Demo.Wpf/Toggles.xaml +++ b/MaterialDesign3.Demo.Wpf/Toggles.xaml @@ -336,11 +336,11 @@ - + - + diff --git a/MaterialDesignThemes.Wpf/ListBoxAssist.cs b/MaterialDesignThemes.Wpf/ListBoxAssist.cs index 430d851c20..068c3d4c0c 100644 --- a/MaterialDesignThemes.Wpf/ListBoxAssist.cs +++ b/MaterialDesignThemes.Wpf/ListBoxAssist.cs @@ -32,7 +32,7 @@ private static void ListBoxMouseButtonEvent(object sender, MouseButtonEventArgs if (listBoxItem is null || !listBoxItem.IsEnabled) return; - listBoxItem.SetCurrentValue(ListBoxItem.IsSelectedProperty, !listBoxItem.IsSelected); + listBoxItem.SetCurrentValue(ListBoxItem.IsSelectedProperty, !GetCanUserToggleSelectedItem(senderElement) || !listBoxItem.IsSelected); mouseButtonEventArgs.Handled = true; listBoxItem.Focus(); @@ -55,4 +55,13 @@ public static void SetIsToggle(DependencyObject element, bool value) public static bool GetIsToggle(DependencyObject element) => (bool)element.GetValue(IsToggleProperty); + + public static readonly DependencyProperty CanUserToggleSelectedItemProperty = DependencyProperty.RegisterAttached( + "CanUserToggleSelectedItem", typeof(bool), typeof(ListBoxAssist), new FrameworkPropertyMetadata(default(bool))); + + public static void SetCanUserToggleSelectedItem(DependencyObject element, bool value) + => element.SetValue(CanUserToggleSelectedItemProperty, value); + + public static bool GetCanUserToggleSelectedItem(DependencyObject element) + => (bool)element.GetValue(CanUserToggleSelectedItemProperty); }