私は WPF リボン 4 を使用していRibbonSplitButton
ます。メニュー項目のドロップダウン メニューを含むコントロールがあります。IsEnabled
プロパティをfalseに設定するRibbonSplitButton
と、ドロップダウンメニューを開くボタンではなく、トップボタンのみが無効になります。
前もって感謝します。
私は WPF リボン 4 を使用していRibbonSplitButton
ます。メニュー項目のドロップダウン メニューを含むコントロールがあります。IsEnabled
プロパティをfalseに設定するRibbonSplitButton
と、ドロップダウンメニューを開くボタンではなく、トップボタンのみが無効になります。
前もって感謝します。
独自の分割ボタンを作成し、RibbonSplitButton から継承し、分割ボタンのみを有効または無効にするためにバインドできる依存関係プロパティを追加することで、この問題を解決しました。
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;
}
}
および XAML では:
<local:MyRibbonSplitButton Label="New" Command="{Binding SomeCommand}"
LargeImageSource="Images/Large/New.png"
ItemsSource="{Binding Templates}"
IsToggleButtonEnabled="{Binding HasTemplates}"/>