在一个WPF应用程序中,我有一个自定义控件。
问题是:工具提示始终显示
自定义控件的
如何使自定义控件的工具提示始终显示当前的属性值?
public class MyControl : Control
{
static MyControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MyControl), new FrameworkPropertyMetadata(typeof(MyControl)));
}
public static readonly DependencyProperty ControlStatusProperty = DependencyProperty.Register("ControlStatus", typeof(int), typeof(MyControl), new PropertyMetadata(16));
public int ControlStatus
{
get
{
return (int)GetValue(ControlStatusProperty);
}
set
{
SetValue(ControlStatusProperty, value);
ChangeVisualState(false);
}
}
...
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
...
ToolTipService.SetToolTip(this, "Status: " + ControlStatus);
}
private void ChangeVisualState(bool useTransitions)
{
...
ToolTipService.SetToolTip(this, "Status: " + ControlStatus);
}
问题是:工具提示始终显示
OnApplyTemplate()
方法执行时的ControlStatus
属性的值。自定义控件的
ControlStatus
属性在运行时已更改,但工具提示仍然始终显示初始值。如何使自定义控件的工具提示始终显示当前的属性值?
"Property1Value: " + Property1 + "\n" + "Property2Value: " + Property2 + "\n"
- remMultiBinding
而不仅仅是Binding
。在MultiBinding
中,您将设置StringFormat
为"Property1Value: {0}\nProperty2Value: {1}\n",并且它的Bindings
集合将包含每个属性的Binding
对象。 - Pavlo Glazkov