我想將代碼中的ToolTip屬性綁定到(Validation.Errors).CurrentItem。我做媒體鏈接,與喜歡的DataGrid:綁定到(Validation.Errors).CurrentItem不適用於TextBox(適用於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")
});
問候,
谷
是網格內的文本框(我的意思是,在一個單元格內)或網格外? – Marcote 2011-03-30 14:27:46
網格只是錯誤標誌的基礎。因此,工具提示是在網格上... – Vale 2011-03-30 14:33:23