当前位置: 首页 > news >正文

WPF 多路绑定、值转换器ValueConvert、数据校验

值转换器 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>

在这里插入图片描述

数据校验

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

http://www.lryc.cn/news/327752.html

相关文章:

  • 【Linux多线程】线程的同步与互斥
  • Linux网卡bond的七种模式详解
  • 【学习笔记】java项目—苍穹外卖day01
  • C++之STL整理(2)之vector超详用法整理
  • 机器学习作业二之KNN算法
  • 笔记81:在服务器中运行 Carla 报错 “Disabling core dumps.”
  • ensp中pc机访问不同网络的服务器
  • CSGO赛事管理系统的设计与实现|Springboot+ Mysql+Java+ B/S结构(可运行源码+数据库+设计文档)
  • win10微软拼音输入法 - bug - 在PATH变量为空的情况下,无法输入中文
  • Java安全篇-Fastjson漏洞
  • Flink系列之:Flink SQL Gateway
  • Linux基础篇:解析Linux命令执行的基本原理
  • LeetCode-热题100:153. 寻找旋转排序数组中的最小值
  • 游戏客户客户端面经
  • 网站业务对接DDoS高防
  • Python-VBA编程500例-024(入门级)
  • 蓝桥杯 - 小明的背包1(01背包)
  • 学习java第二十六天
  • Go第三方框架--gin框架(二)
  • 五分钟搞懂UDS刷写34/36/37服务(内含S19文件解读)
  • 知识图谱智能问答系统技术实现
  • 【unity】如何汉化unity编译器
  • 为什么Python不适合写游戏?
  • 查询优化-提升子查询-UNION类型
  • 【数据结构 | 图论】如何用链式前向星存图(保姆级教程,详细图解+完整代码)
  • 气象预测新篇章:Python人工智能的变革力量
  • 基于微信小程序的民宿短租系统设计与实现(论文+源码)_kaic
  • vue3开发前端表单缓存自定义指令,移动端h5必备插件
  • 骗子查询系统源码
  • 目标检测+车道线识别+追踪