2010-04-07 5 views
1

리본 단추의 내용을 변경하는 방법이 있습니까?WPF 리본 컨트롤 - 리본 단추의 내용 변경

나는 RibbonButton에 이미지와 레이블이 있지만 그 내용에 모양 (Rectangle 클래스)이있는 단추를 원한다는 것을 알고 있으며이 단추에는 RibbonButton 스타일이 적용되어 있어야합니다. 그것을 할 방법이 있습니까?

답변

1

왜 독자적인 버튼 컨트롤을 만들지 않습니까?

XAML : 뒤에

<Button x:Class="MyApp.myButton" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     mc:Ignorable="d" 
     d:DesignHeight="71" d:DesignWidth="87"> 
    <Rectangle Height="40" Width="40" Fill="#FFC11414" /> 

코드 :

public partial class myButton : Button, IRibbonControl 
{ 

    public myButton() 
    { 
     InitializeComponent(); 
     Type forType = typeof(myButton); 
     FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(forType, new FrameworkPropertyMetadata(forType)); 
     ButtonBase.CommandProperty.OverrideMetadata(forType, new FrameworkPropertyMetadata(new PropertyChangedCallback(OnCommandChanged))); 
     FrameworkElement.ToolTipProperty.OverrideMetadata(forType, new FrameworkPropertyMetadata(null, new CoerceValueCallback(RibbonButton.CoerceToolTip))); 
     ToolTipService.ShowOnDisabledProperty.OverrideMetadata(forType, new FrameworkPropertyMetadata(true)); 
    } 
    public static object CoerceToolTip(DependencyObject d, object value) 
    { 
     if (value == null) 
     { 
      RibbonButton button = (RibbonButton)d; 
      RibbonCommand command = button.Command as RibbonCommand; 
      if ((command == null) || ((string.IsNullOrEmpty(command.ToolTipTitle) && string.IsNullOrEmpty(command.ToolTipDescription)) && (command.ToolTipImageSource == null))) 
      { 
       return value; 
      } 
      value = new RibbonToolTip(command); 
     } 
     return value; 
    } 
    private static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
    { 
     ((myButton)d).CoerceValue(FrameworkElement.ToolTipProperty); 
    } 
} 
관련 문제