Binding的参数用法

本文详细介绍了 WPF 中的数据绑定机制,包括不同绑定模式的作用及使用场景,如 oneTime、oneWay、twoWay 和 oneWayToSource。同时,还解释了如何通过 ElementName 指定绑定的目标控件,以及 UpdateSourceTrigger 的触发方式,如 lostFocus 和 propertyChanged。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    <Label Name="lblName" Height="28" HorizontalAlignment="Left" Margin="66,28,0,0" VerticalAlignment="Top" Width="93">Name</Label>
        <Label Name="lblDate" Height="28" HorizontalAlignment="Left" Margin="66,62,0,0" VerticalAlignment="Top" Width="85">Date</Label>
        <Label Name="lblContent" Margin="66,96,291,0"  Height="28" VerticalAlignment="Top">content</Label>
        <TextBox Height="23" Margin="165,28,157,0" Name="txtName" VerticalAlignment="Top"  Text="NameString"/>
        <TextBox Height="23" Margin="165,62,157,0" Name="txtDate" VerticalAlignment="Top" />
        <TextBox Height="23" Margin="165,96,157,0" Name="txtContent" VerticalAlignment="Top" />
        <TextBox Margin="74,130,157,0" Name="label6" Text="{Binding Mode=oneTime, ElementName=txtName ,Path=Text, UpdateSourceTrigger=propertyChanged }" Height="28" VerticalAlignment="Top"></TextBox>
        <!--                                                                                      绑定 Mode属性指定oneTime 只绑定一次 oneway 单项绑定 twoway双向绑定 onwayToSource单项目标改变源被改变-->
        <!--                                                                                      ElementName 指定需要绑定的空间名称-->
        <!--                                                                                      Path 指定需要绑定控件的属性-->
        <!--                                                                                      UpdateSourceTrigger源空更新触发器 lostfocus 鼠标失去焦点是触发 propertyChanged属性改变时触发-->
        <TextBox Height="28" Margin="74,0,157,71" Name="label4" VerticalAlignment="Bottom" Text="{Binding Mode=twoWay, ElementName=txtDate,Path=Text,UpdateSourceTrigger=lostfocus}"></TextBox>
        <TextBox Height="28" Margin="74,0,157,37" Name="label5" VerticalAlignment="Bottom" Text="{Binding Mode=onewaytosource, ElementName=txtContent, Path=Text,UpdateSourceTrigger=propertyChanged}"></TextBox>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值