在我的应用程序中,我对DataGridTemplateColumn
具有以下定义:
<DataGridTemplateColumn Header="Placeholder-Name" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox IsEditable="True" VerticalAlignment="Center" Margin="2"
ItemsSource="{Binding DataContext.AvailablePlaceholders, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}"
DisplayMemberPath="PlaceholderName"
Validation.ErrorTemplate="{StaticResource ComboBoxErrorTemplate}">
<ComboBox.Text>
<Binding Path="PlaceholderName" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<local:PlaceholderValidationRule>
<local:PlaceholderValidationRule.PlaceholderValidationRuleParamData>
<local:PlaceholderValidationRuleParamData
UsedPlaceholders="{Binding Source={StaticResource proxy}, Path=Data.PlaceholderItems}"
AvailablePlaceholders="{Binding Source={StaticResource proxy}, Path=Data.AvailablePlaceholders}"/>
</local:PlaceholderValidationRule.PlaceholderValidationRuleParamData>
</local:PlaceholderValidationRule>
</Binding.ValidationRules>
</Binding>
</ComboBox.Text>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
一切正常,但是我刚刚意识到,如果PlaceholderValidationRule报告的结果无效,则ComboBox
-Text绑定到的ViewModel中的PlaceholderName属性将不会更新。
如果存在验证错误,是否还可以通过视图从View更新ViewModel中的属性?
答案 0 :(得分:2)
如果存在验证错误,是否还可以通过视图从View更新ViewModel中的属性?
将ValidationStep
的{{1}}属性设置为ValidationRule
:
UpdatedValue
这将导致在更新源属性后 运行验证规则。