我試圖設置DataGridCells的Validation.ErrorTemplate,這裏的XAML代碼:DataGridCell Validation.ErrorTemplate忽略
<Style x:Key="{x:Type DataGridCell}" x:Uid="dataGridCellErrorTemplate" TargetType="{x:Type DataGridCell}">
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate >
<Border BorderBrush="Green" BorderThickness="2" ToolTip="Heidenei"></Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<!-- following line only for demonstration that the setter is working ... -->
<Setter Property="Background" Value="Aquamarine"></Setter>
</Style>
而datagridcells的背景下被成功標記爲綠色(任何驗證結果獨立的)使用的Validation.ErrorTemplate仍然是默認的,即紅色邊框。
我知道這裏有類似的問題,在計算器中,例如, Styling DataGridCell Error Template 但他們並沒有真正解決我的問題。
任何幫助表示讚賞
弗蘭克
[因爲編輯控件在運行時創建的,你不能像你會與簡單的控制使用Validation.ErrorTemplate附加屬性(http://msdn.microsoft.com/en-us/library/ ee622975.aspx)。您可能必須在渲染後執行此操作('DispatcherTimer') – 2012-03-15 15:05:34
感謝您的反饋,但我不確定是否瞭解它。在我的場景中,datagridcells不由用戶編輯(因此不需要編輯控件),而是由後臺進程編輯。我仍然想使用IDataErrorInfo來突出顯示那些有問題值的字段。 – FrankE 2012-03-16 06:41:09
當他們說「編輯控件」時,(我認爲)他們的意思是「每個DataGridCell中嵌入的控件」。換句話說,Template可能會被應用到單元格中,但是當內部控件被創建時它會被覆蓋。這就是爲什麼當創建一個Row時你可能需要捕獲,並且通過每個單元循環來設置你自己的值。 – 2012-03-16 13:54:19