为什么我使用UpdateSourceTrigger = PropertyChanged,TwoWay还不够? [英] Why am i using UpdateSourceTrigger=PropertyChanged ,TwoWay is not enough?

查看:325
本文介绍了为什么我使用UpdateSourceTrigger = PropertyChanged,TwoWay还不够?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨;有源文本框和目标文本框txttarget具有对txtsource的绑定.在txtsource中写东西时,txttarget改变了.一切都很好.但是在txttarget上书写时,我在txttarget上看不到任何变化吗?有双向模式.单向模式还不够吗?不用"UpdateSourceTrigger = PropertyChanged"该怎么写?


   <Grid>
        <TextBox Height="23" HorizontalAlignment="Left" Margin="155,62,0,0" Name="txtSource" VerticalAlignment="Top" Width="120" />
        <TextBox Height="23" HorizontalAlignment="Left"
                 Text="{Binding ElementName=txtSource,Path=Text,Mode=TwoWay}" 
                 Margin="155,113,0,0" Name="txtTarget" VerticalAlignment="Top" Width="120" />
    </Grid>

解决方案

txtTarget.Text每当绑定源(txtSource.Text)更改时都会更新.

绑定模式为TwoWay,这意味着对txtTarget.Text的更改将反映到绑定的源.什么时候?这取决于Binding.UpdataSourceTrigger属性.

如果您希望目标绑定在更改时更新源绑定,则必须使用 Binding.UpdataSourceTrigger = OnPropertyChanged,否则当txtTarget失去焦点时(默认行为),您将更新绑定源.

hi; there are Source and target textbox txttarget has a binding to txtsource. when writing something in txtsource, txttarget is changed.Everything is good. But writing on txttarget, i dont see any changes at txttarget? there is TwoWay mode. Twoway mode is not enough? can i write without using "UpdateSourceTrigger=PropertyChanged"?


   <Grid>
        <TextBox Height="23" HorizontalAlignment="Left" Margin="155,62,0,0" Name="txtSource" VerticalAlignment="Top" Width="120" />
        <TextBox Height="23" HorizontalAlignment="Left"
                 Text="{Binding ElementName=txtSource,Path=Text,Mode=TwoWay}" 
                 Margin="155,113,0,0" Name="txtTarget" VerticalAlignment="Top" Width="120" />
    </Grid>

解决方案

txtTarget.Text is updated whenever the bound source (txtSource.Text) changes.

The binding mode is TwoWay which means that changes to txtTarget.Text will be reflected to the bound source. When? It depends on the Binding.UpdataSourceTrigger property.

If you want your target binding to update your source binding when changing you must use Binding.UpdataSourceTrigger = OnPropertyChanged, otherwise you will update the binding source when txtTarget losts focus (default behavior).

这篇关于为什么我使用UpdateSourceTrigger = PropertyChanged,TwoWay还不够?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆