我想在验证错误发生时修改“Template10.Validation”样式。 这是我的目标风格。
我试过......但是有一些奇怪的错误......
<validate:ControlWrapper Property="{Binding SettingEmailModel}" PropertyName="EmailReceivers">
<validate:ControlWrapper.Template>
<ControlTemplate TargetType="validate:ControlWrapper">
<StackPanel DataContext="{TemplateBinding Property}">
<TextBlock Text="IsValid" />
<TextBlock Text="{Binding IsValid}" />
<TextBlock Text="Errors" />
<TextBlock Text="{Binding Errors.Count}" />
<ContentPresenter Content="{TemplateBinding Content}" />
<TextBlock x:Name="ValidationNotifyTextBlock" Text="{Binding Errors[0]}">
<Interactivity:Interaction.Behaviors>
<Core:DataTriggerBehavior Binding="{Binding IsValid}" Value="True">
<Core:ChangePropertyAction TargetObject="{Binding ElementName=ValidationNotifyTextBlock}"
PropertyName="Foreground" Value="Red"/>
</Core:DataTriggerBehavior>
<Core:DataTriggerBehavior Binding="{Binding IsValid}" Value="False">
<Core:ChangePropertyAction TargetObject="{Binding ElementName=ValidationNotifyTextBlock}"
PropertyName="Foreground" Value="Black"/>
</Core:DataTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</TextBlock>
</StackPanel>
</ControlTemplate>
</validate:ControlWrapper.Template>
<Grid>
<TextBox Text="{Binding SettingEmailModel.EmailReceivers, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
MinHeight="400" Style="{StaticResource SettingStyle_MultilineTextBox}"/>
</Grid>
</validate:ControlWrapper>
这是错误消息“Collection property __implicit_propery is null”
1)我尝试了版本1.1和版本2.0的“Microsoft.Xaml.Behaviors.Uwp.Managed”
我不知道为什么会发生错误.. 请给我建议,或者你能为我的设计制作一个风格吗?
答案 0 :(得分:0)
根据您的要求,您可以为已经验证的ErrorTextBoxStyle
创建TextBox
。并在以下ControlWrapper
ControlTemplate。
<validate:ControlWrapper PropertyName="FirstName">
<validate:ControlWrapper.Template>
<ControlTemplate TargetType="validate:ControlWrapper">
<Grid>
<ContentPresenter Content="{TemplateBinding Content}"/>
</Grid>
</ControlTemplate>
</validate:ControlWrapper.Template>
<TextBox
Width="{StaticResource FieldWidth}"
Header="First Name"
Text="{Binding FirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<Interactivity:Interaction.Behaviors>
<behaviors:ValidationBehavior PropertyName="FirstName">
<behaviors:ValidationBehavior.WhenValidActions>
<Core:ChangePropertyAction PropertyName="Style" Value="{x:Null}" />
</behaviors:ValidationBehavior.WhenValidActions>
<behaviors:ValidationBehavior.WhenInvalidActions>
<Core:ChangePropertyAction PropertyName="Style" Value="{StaticResource ErrorTextBoxStyle}" />
</behaviors:ValidationBehavior.WhenInvalidActions>
</behaviors:ValidationBehavior>
</Interactivity:Interaction.Behaviors>
</TextBox>
</validate:ControlWrapper>
<强> ErrorTextBoxStyle 强>
<Style x:Key="ErrorTextBoxStyle" TargetType="TextBox">
<Setter Property="Foreground" Value="White" />
<Setter Property="BorderBrush" Value="Red"/>
</Style>