【发布时间】:2011-03-20 21:16:43
【问题描述】:
当我在 WPF 自定义控件中设置工具提示绑定时,它可以完美运行:
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
...
SetBinding(ToolTipProperty, new Binding
{
Source = this,
Path = new PropertyPath("Property1"),
StringFormat = "ValueOfProp1: {0}"
});
}
但是当我尝试使用 MultiBinding 在 ToolTip 中有几个属性时,它不起作用:
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
...
MultiBinding multiBinding = new MultiBinding();
multiBinding.StringFormat = "ValueOfProp1: {0}\nValueOfProp2: {1}\nValueOfProp3: {2}\n";
multiBinding.Bindings.Add(new Binding
{
Source = this,
Path = new PropertyPath("Property1")
});
multiBinding.Bindings.Add(new Binding
{
Source = this,
Path = new PropertyPath("Property2")
});
multiBinding.Bindings.Add(new Binding
{
Source = this,
Path = new PropertyPath("Property3")
});
this.SetBinding(ToolTipProperty, multiBinding);
}
在这种情况下,我根本没有显示工具提示。
我哪里错了?
【问题讨论】:
标签: c# wpf silverlight custom-controls tooltip