Reputation: 11
I am using WPF Ribbon 4. I have a RibbonSplitButton
control with dropdown menu of menu items.
When I set IsEnabled
property of RibbonSplitButton
to false only top button becomes disabled, not the button which opens dropdown menu.
Thanks in advance.
Upvotes: 1
Views: 2599
Reputation: 11
You can simply add a DropDownOpened="RibbonMenuButton_OnDropDownOpened" to the WPF and then
private void RibbonMenuButton_OnDropDownOpened(object sender, EventArgs e)
{
var rsb = sender as RibbonSplitButton;
if (rsb == null) return;
if (DataContext is GameCardViewModel vm)
{
rsb.IsDropDownOpen = vm.EasyInputMode;
}
}
Upvotes: 0
Reputation: 91
I solved this problem by creating my own split button, inheriting from RibbonSplitButton and adding an dependency property that I can bind to for enabling or disabling the split button alone.
public class MyRibbonSplitButton : RibbonSplitButton
{
public MyRibbonSplitButton()
: base()
{
}
/// <summary>
/// Gets or sets a value indicating whether the toggle button is enabled.
/// </summary>
/// <value><c>true</c> if the toggle button should be enabled; otherwise, <c>false</c>.</value>
public bool IsToggleButtonEnabled
{
get { return (bool)GetValue(IsToggleButtonEnabledProperty); }
set { SetValue(IsToggleButtonEnabledProperty, value); }
}
/// <summary>
/// Identifies the <see cref="IsToggleButtonEnabled"/> dependency property
/// </summary>
public static readonly DependencyProperty IsToggleButtonEnabledProperty =
DependencyProperty.Register(
"IsToggleButtonEnabled",
typeof(bool),
typeof(MyRibbonSplitButton),
new UIPropertyMetadata(true, new PropertyChangedCallback(MyRibbonSplitButton.ToggleButton_OnIsEnabledChanged)));
/// <summary>
/// Handles the PropertyChanged event for the IsToggleButtonEnabledProperty dependency property
/// </summary>
private static void ToggleButton_OnIsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
{
var button = sender as MyRibbonSplitButton;
var toggleButton = button.GetTemplateChild("PART_ToggleButton") as RibbonToggleButton;
toggleButton.IsEnabled = (bool)e.NewValue;
}
}
and in XAML:
<local:MyRibbonSplitButton Label="New" Command="{Binding SomeCommand}"
LargeImageSource="Images/Large/New.png"
ItemsSource="{Binding Templates}"
IsToggleButtonEnabled="{Binding HasTemplates}"/>
Upvotes: 1