2016-08-03 6 views
1

TextBox 용 리본 외부에서 RibbonToolTip을 사용하고 싶습니다.RibbonToolTip을 전역 도구 설명으로 설정하는 방법

긴 방법은 다음과 같습니다

<TextBox Text="{Binding Name}"> 
    <TextBox.ToolTip> 
    <RibbonToolTip Title="{DynamicResource nameTitle}" Description="{DynamicResource nameDescription}"/> 
    </TextBox.ToolTip> 
</TextBox> 

내가 대신

<TextBox Text="{Binding Name}" ToolTipTitle="{DynamicResource nameTitle}" ToolTipDescription="{DynamicResource nameDescription}"/> 

내가

<Style TargetType="TextBox"> 
    <Setter Property="ToolTip" > 
    <Setter.Value> 
     <RibbonToolTip/> 
    </Setter.Value> 
    </Setter> 
</Style> 

하지만 어떻게 제목을 설정하는 방법과 함께 RibbonToolTip을 설정할 수 있습니다 이런 식으로 뭔가를 사용하려면 기술.

ToolTipTitle 및 ToolTipDescription에 대한 새 종속성 개체를 만들려면 TextBox에서 새 클래스를 파생하지 않으면 어떤 방법이 있습니까?

<TextBox ToolTip.Title="Name" ... 

도 도구 설명이 입력되지 않아 작동하지 않습니다.

답변

0

답변은 첨부 된 속성입니다. 이 클래스와

public class ExToolTip : DependencyObject 
    { 
     public static readonly DependencyProperty TitleProperty = DependencyProperty.RegisterAttached("Title", typeof(string), typeof(ExToolTip), new PropertyMetadata("", OnTitleChanged)); 

     public static string GetTitle(DependencyObject o) 
     { 
      return (string)o.GetValue(TitleProperty); 
     } 

     public static void SetTitle(DependencyObject o, string value) 
     { 
      o.SetValue(TitleProperty, value); 
     } 

     private static void OnTitleChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) 
     { 
      FrameworkElement fe = o as FrameworkElement; 
      if (fe != null) 
      { 
       if (fe.ToolTip == null) 
       { 
        fe.ToolTip = new RibbonToolTip(); 

       } 
       RibbonToolTip rtt = fe.ToolTip as RibbonToolTip; 
       if (rtt != null) 
       { 
        rtt.Title = (string)e.NewValue; 
       } 
      } 
     } 

     public static readonly DependencyProperty DescriptionProperty = DependencyProperty.RegisterAttached("Description", typeof(string), typeof(ExToolTip), new PropertyMetadata("", OnDescriptionChanged)); 

     public static string GetDescription(DependencyObject o) 
     { 
      return (string)o.GetValue(DescriptionProperty); 
     } 

     public static void SetDescription(DependencyObject o, string value) 
     { 
      o.SetValue(DescriptionProperty, value); 
     } 

     private static void OnDescriptionChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) 
     { 
      FrameworkElement fe = o as FrameworkElement; 
      if (fe != null) 
      { 
       if (fe.ToolTip == null) 
       { 
        fe.ToolTip = new RibbonToolTip(); 

       } 
       RibbonToolTip rtt = fe.ToolTip as RibbonToolTip; 
       if (rtt != null) 
       { 
        rtt.Description = (string)e.NewValue; 
       } 
      } 
     } 
    } 

난 쉽게 작성할 수 있습니다

<TextBox Text="{Binding Text}" ExToolTip.Title="title" ExToolTip.Description="Description" />