简体   繁体   中英

C# UWP Template10.Validation Change Style

With " Template10.Validation ", I want to change style.

First I made this Style for "validate:ControlWrapper".

<Style TargetType="validate:ControlWrapper">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="validate:ControlWrapper">
                <StackPanel>

                    <ContentPresenter Content="{TemplateBinding Content}" />

                    <ItemsControl ItemsSource="{Binding Errors, Source={TemplateBinding Properties[PropertyName]}}" >
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Foreground="Red" Text="{Binding}" Visibility="{Binding IsValid}"/>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>


                </StackPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

and Here is the result.

在此处输入图片说明

Something is strange. because I want to display Validation warning message for ONLY first name. but It display every warning. from address, from postal code.

My main quesiton How to access "ValidatableModelBase.Property["PropertyName"].Errors" in Xaml. because [] branket is not possible to use in XAML binding. How to accesss ??

with lot of my time, I finally find a solution for my own question...

First is my model class.

public class SettingEmail
    : Template10.Validation.ValidatableModelBase
{public string EmailReceivers { get { return Read<string>(); } set { Write(value); } }}

Next is Property to bind. ( in my ViewModel class )

public SettingEmail SettingEmailModel{ get { return se; } set { this.Set(ref se, value); } }

Next is XAML code.

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

and Last is Style in Resource file.

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

I hope it help someone. and I am sorry with my poor question's descriptions...I will try improve next...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM