C#UWP模板10.验证更改样式
使用“”时,我想更改样式 首先,我为“validate:ControlWrapper”制作了这种样式C#UWP模板10.验证更改样式,c#,validation,uwp,template10,C#,Validation,Uwp,Template10,使用“”时,我想更改样式 首先,我为“validate:ControlWrapper”制作了这种样式 这是结果 有点奇怪。因为我只想显示名字的验证警告消息。但它显示了每一个警告。从地址,从邮政编码 我的主要问题 如何访问Xaml中的“ValidableModelbase.Property[“PropertyName”].Errors”。 因为[]branket无法在XAML绑定中使用。如何访问???花了很多时间,我终于找到了解决我自己问题的方法 首先是我的模型课 public class
这是结果
有点奇怪。因为我只想显示名字的验证警告消息。但它显示了每一个警告。从地址,从邮政编码
我的主要问题
如何访问Xaml中的“ValidableModelbase.Property[“PropertyName”].Errors”。
因为[]branket无法在XAML绑定中使用。如何访问???花了很多时间,我终于找到了解决我自己问题的方法 首先是我的模型课
public class SettingEmail
: Template10.Validation.ValidatableModelBase
{public string EmailReceivers { get { return Read<string>(); } set { Write(value); } }}
接下来是XAML代码
<validate:ControlWrapper DataContext="{Binding SettingEmailModel}"
PropertyName="EmailReceivers"
Style="{StaticResource validationNotify}">
<TextBox Text="{Binding EmailReceivers, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
MinHeight="400" Style="{StaticResource SettingStyle_MultilineTextBox}"/>
</validate:ControlWrapper>
最后是资源文件中的样式
<Style x:Key="validationNotify" TargetType="validate:ControlWrapper">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="validate:ControlWrapper">
<StackPanel >
<ContentPresenter Content="{TemplateBinding Content}"/>
<ItemsControl DataContext="{TemplateBinding Property}"
ItemsSource="{Binding Errors, Source={TemplateBinding Property}}"
Style="{StaticResource validationNotifyMessage}"
>
<ItemsControl.ItemTemplate >
<DataTemplate>
<StackPanel>
<TextBlock Foreground="Red" Text="{Binding}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我希望它能帮助别人。
我对我糟糕的问题的描述感到抱歉…我将尝试改进下一步…不要使用引号,您可以在XAML中使用方括号,请参见我的。您可以使用以下内容简化答案中的代码
<validate:ControlWrapper DataContext="{Binding SettingEmailModel}"
PropertyName="EmailReceivers"
Style="{StaticResource validationNotify}">
<TextBox Text="{Binding EmailReceivers, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
MinHeight="400" Style="{StaticResource SettingStyle_MultilineTextBox}"/>
</validate:ControlWrapper>
<Style x:Key="validationNotify" TargetType="validate:ControlWrapper">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="validate:ControlWrapper">
<StackPanel >
<ContentPresenter Content="{TemplateBinding Content}"/>
<ItemsControl DataContext="{TemplateBinding Property}"
ItemsSource="{Binding Errors, Source={TemplateBinding Property}}"
Style="{StaticResource validationNotifyMessage}"
>
<ItemsControl.ItemTemplate >
<DataTemplate>
<StackPanel>
<TextBlock Foreground="Red" Text="{Binding}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>