0
点赞
收藏
分享

微信扫一扫

【Vscode】无法将“python,pip,node,npm等”识别为cmdlet...问题

陬者 04-03 07:30 阅读 3
wpf

值转换器 valueconvert

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
使用ValueConverter需要实现IValueConverter接口,其内部有两个方法,Convert和ConvertBack。我们在使用Binding绑定数据的时候,当遇到源属性和目标控件需要的类型不一致的,就可以使用ValueConverter,它就相当于一个桥,当数据从源到目标控件时,需要走Convert方法,我们在这个方法里边就可以自定义转换逻辑,当数据从目标控件到源时,需要走ConvertBack方法,我们可以在这里边自定义回转逻辑。

多路绑定

在这里插入图片描述

<Window x:Class="DEMO2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DEMO2" xmlns:sys="http://schemas.microsoft.com/winfx/2009/xaml"
        mc:Ignorable="d"      
   
       Title="333"
        Height="450" Width="800"  >
    <Window.Resources>
        <ResourceDictionary>
            <local:HasValuesMultiConvert x:Key="HAS"></local:HasValuesMultiConvert>
        </ResourceDictionary>
    </Window.Resources>
    <Grid MouseDown="Grid_MouseDown" Background="Green">
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <TextBox x:Name="txt1" Grid.Row="0"></TextBox>
        <TextBox x:Name="txt2" Grid.Row="1"></TextBox>
        <Button Grid.Row="2"  Content="登录" FontSize="20">
            <Button.IsEnabled>
                <MultiBinding Converter="{StaticResource HAS}" UpdateSourceTrigger="PropertyChanged">
                    <Binding Path="Text" Source="{x:Reference txt1}"></Binding>
                    <Binding Path="Text" Source="{x:Reference txt2}"></Binding>
                </MultiBinding>
            </Button.IsEnabled>
        </Button>
    </Grid>
</Window>

在这里插入图片描述

数据校验

在这里插入图片描述
在这里插入图片描述

举报

相关推荐

0 条评论