使用「Template10.Validation」,我想更改樣式。C#UWP Template10.Validation更改樣式
首先,我將此樣式設置爲「驗證:ControlWrapper」。
<Style TargetType="validate:ControlWrapper">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="validate:ControlWrapper">
<StackPanel>
<ContentPresenter Content="{TemplateBinding Content}" />
<ItemsControl ItemsSource="{Binding Errors, Source={TemplateBinding Properties[PropertyName]}}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Foreground="Red" Text="{Binding}" Visibility="{Binding IsValid}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
這就是結果。
東西很奇怪。因爲我想爲唯一的名字顯示驗證警告消息。但它顯示每一個警告。從地址,郵政編碼。
我的主要quesiton 如何訪問 「ValidatableModelBase.Property [」 屬性名 「]。錯誤」 在XAML。 ,因爲[] branket無法在XAML綁定中使用。如何訪問?
不要使用引號,您可以在XAML中使用方括號,請參閱我的[驗證與棱鏡示例](https:/ /github.com/bartlannoeye-com/2017-01-UWPValidation/blob/master/Src/Validation/Views/MainPage.xaml#L24)。 – Bart