为什么我使用UpdateSourceTrigger = PropertyChanged,TwoWay还不够? [英] Why am i using UpdateSourceTrigger=PropertyChanged ,TwoWay is not enough?
问题描述
<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屋!