[英]Fire routed event when tooltip is changed
I am trying to add routed event to existed tooltip in control - now it is bound to simple get/set property. 我试图将路由事件添加到控件中现有的工具提示-现在将其绑定到简单的get / set属性。
binding in xaml: 在XAML中绑定:
<Style x:Key="Style" TargetType="{x:Type myControl}">
<Setter Property="ToolTip" Value="{Binding Name}" />
prop in myControl: myControl中的prop:
public string Name
{
get;
set;
}
routed event in Control Class that contains list of myControls (I suppose I have wrote it in the right way) 包含myControls列表的Control类中的路由事件(我想我已经用正确的方式编写了该事件)
public static readonly RoutedEvent TooltipChangedEvent = EventManager.RegisterRoutedEvent("ToolTipChanged", RoutingStrategy.Bubble, typeof(RoutedPropertyChangedEventHandler<string>), typeof(Control));
public event RoutedPropertyChangedEventHandler<string> ToolTipChanged
{
add
{
AddHandler(TooltipChangedEvent, value);
}
remove
{
RemoveHandler(TooltipChangedEvent, value);
}
}
the question is how to fire this event when tooltip is changed? 问题是更改工具提示时如何触发此事件?
class MainViewModel : FrameworkElement, INotifyPropertyChanged
{
private string _name;
public string Name
{
get { return _name; }
set
{
_name = value;
RaiseEvent(new RoutedEventArgs(TooltipChangedEvent));
OnPropertyChanged();
}
}
public static readonly RoutedEvent TooltipChangedEvent = EventManager.RegisterRoutedEvent("ToolTipChanged", RoutingStrategy.Bubble, typeof(RoutedPropertyChangedEventHandler<string>), typeof(Control));
public event RoutedPropertyChangedEventHandler<string> ToolTipChanged
{
add
{
AddHandler(TooltipChangedEvent, value);
}
remove
{
RemoveHandler(TooltipChangedEvent, value);
}
}
public void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.