Template10.Validation/UWP/C# Как сделать новый дизайн? , ошибка: свойство коллекции __implicit_propery равно null

Я хочу изменить стиль "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>                                                                                                           

Вот сообщение об ошибке "Свойство коллекции __implicit_propery равно null"

введите здесь описание изображения

1) Я пробовал версии 1.1 и 2.0 "Microsoft.Xaml. .Behaviors.Uwp.Управляемый"

Я не знаю, почему произошла ошибка. Пожалуйста, посоветуйте мне или, можете ли вы создать стиль для моего дизайна?


person Kazuhiko Nakayama    schedule 20.09.2017    source источник


Ответы (1)


По вашему требованию вы можете создать 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>

Стиль ErrorTextBox

<Style x:Key="ErrorTextBoxStyle" TargetType="TextBox">
    <Setter Property="Foreground" Value="White" />
    <Setter Property="BorderBrush"  Value="Red"/>
</Style>

введите здесь описание изображения

person Nico Zhu - MSFT    schedule 21.09.2017