Silverlight DataGrid验证显示所有对象|属性的验证错误 [英] Silverlight DataGrid validation show validation error for all objects|properties
问题描述
我有一个ObservableCollection < T>
,其中T:INotifyDataErrorInfo.
I have a ObservableCollection<T>
where T: INotifyDataErrorInfo.
此集合中的对象存在验证错误,然后将此集合绑定到Silverlight 4 DataGrid,有没有办法在DataGrid中显示此验证错误?(为每个对象的无效属性显示红色单元格).默认情况下,DataGrid仅在我开始编辑行时才显示验证错误,并且仅对活动行显示.
Objects in this collection have validation errors, then I bind this collection to Silverlight 4 DataGrid, is there a way to show this validation error in DataGrid? (show red cell for invalid properties for each object). By default DataGrid show validation error only when I begin to edit row, and only for active row.
推荐答案
我没有成功使用 TextBlock
控件,因此我使用了禁用的 TextBox
您可以更改 TextBox
的模板,我的意思是删除边框并将其背景设置为真正透明.
I haven't succeeded with a TextBlock
control, so I used a disabled TextBox
You can change the template of the TextBox
, I mean to remove border and to set its background really transparent.
<sdk:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Items}" IsReadOnly="False" SelectionMode="Single">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="Title" Binding="{Binding Title}"/>
<sdk:DataGridTemplateColumn Header="Link" Width="100">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Link, Mode=TwoWay}" Margin="2"
IsEnabled="False" BorderThickness="0" Background="Transparent"/>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
<sdk:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox Text="{Binding Link, Mode=TwoWay}" Margin="2"/>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellEditingTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
这篇关于Silverlight DataGrid验证显示所有对象|属性的验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!