Search code examples
c#uwptemplate10

Template10.Validation/UWP/C# How to make new design ? , error : Collection property __implicit_propery is null


I want to modify "Template10.Validation" style when Validation error is happened. Here is my Target style.

enter image description here

and I tried .. but There is strange errors...

<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>                                                                                                           

Here is error message "Collection property __implicit_propery is null"

enter image description here

1) I tried both ver 1.1 and ver 2.0 of "Microsoft.Xaml.Behaviors.Uwp.Managed"

I do not know why the error is happened.. Please advice me or, Can you make a style for my design ?


Solution

  • For your requirement, you could create ErrorTextBoxStyle for the TextBox that has been verifyed. And use it in the follwing 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>
    

    enter image description here