【发布时间】:2011-07-26 03:30:25
【问题描述】:
我正在尝试将 ToolTip 属性绑定到代码中的 (Validation.Errors).CurrentItem。我已经用 DataGrid 做到了,比如:
var grid = new FrameworkElementFactory(typeof(Grid));
grid.SetValue(Grid.ToolTipProperty, new Binding() {
RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(DataGridRow), 1),
Path = new PropertyPath("(Validation.Errors).CurrentItem.ErrorContent")
});
这行得通,错误符号出现在带有工具提示的行标题中(一些错误文本)。
当我尝试对文本框执行相同操作时,工具提示不会出现:
grid.SetValue(Grid.ToolTipProperty, new Binding() {
ElementName = textBox1.Name, // tried with relative source also...
Path = new PropertyPath("(Validation.Errors).CurrentItem.ErrorContent")
});
问候,
谷
【问题讨论】:
-
TextBox 是在网格内(我的意思是在单元格内)还是在网格外?
-
网格只是错误标志的基础。所以工具提示是在一个网格上......
标签: c# wpf validation binding