Monitor for all validation events

后端 未结 1 942
灰色年华
灰色年华 2021-01-29 06:36

It\'s quite easy to check if certain container or its children have validation errors. This can be used to disable Save button.

I can use timer



        
相关标签:
1条回答
  • 2021-01-29 06:53

    The way I usually handle this is illustrated here:

    https://social.technet.microsoft.com/wiki/contents/articles/28597.aspx

    The errorevent will bubble to a container and you can handle that, use a behavior or command to pass it to the viewmodel.

    Like:

    <ControlTemplate x:Key="AddingTriggers" TargetType="ContentControl">
        <ControlTemplate.Resources>
            <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource ErrorToolTip}">
                <Setter Property="HorizontalAlignment" Value="Left"/>
            </Style>
    
        </ControlTemplate.Resources>
        <StackPanel>
            <i:Interaction.Triggers>
                <local:RoutedEventTrigger RoutedEvent="{x:Static Validation.ErrorEvent}">
                    <e2c:EventToCommand   Command="{Binding ConversionErrorCommand, Mode=OneWay}"
                                            EventArgsConverter="{StaticResource BindingErrorEventArgsConverter}"
                                            PassEventArgsToCommand="True" />
                </local:RoutedEventTrigger>
            </i:Interaction.Triggers>
            <TextBlock Text="This would be some sort of a common header" Foreground="LightBlue" HorizontalAlignment="Right"/>
            <ContentPresenter/> <!-- This is how you can have variable content "within" the control -->
            <TextBlock Text="This would some sort of a common footer" Foreground="LightBlue"  HorizontalAlignment="Right"/>
        </StackPanel>
    </ControlTemplate>
    

    You need NotifyOnValidationError=True on any bindings.

    0 讨论(0)
提交回复
热议问题