2011-11-22 2 views

답변

1

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}"/> 
+0

까지 그냥 머리를; 이 방법을 사용하면 IsToggleButtonEnabled가 false 일 때 버튼의 텍스트가 비활성화 (회색)로 렌더링됩니다. – eilef