为什么我使用UpdateSourceTrigger = PropertyChanged,TwoWay还不够?

lok*_*oki 9 .net c# wpf xaml propertychanged

喜; 有源文件框和目标文本框txttarget有一个绑定到txtsource.当在txtsource中写一些东西时,txttarget就会改变.一切都很好.但是在txttarget上写道,我在txttarget上看不到任何变化?有TwoWay模式.Twoway模式还不够?我可以在不使用"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>
Run Code Online (Sandbox Code Playgroud)

Kla*_*s78 21

txtTarget.Text每当绑定的source(txtSource.Text)更改时更新.

绑定模式TwoWay意味着更改txtTarget.Text将反映到绑定源.什么时候?这取决于Binding.UpdataSourceTrigger财产.

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


shf*_*301 17

默认UpdateSourceTriggerTextBoxLostFocus(见Binding.UpdateSourceTrigger).如果未指定PropertyChanged为UpdateSourceTrigger,则输入的内容txtTarget将不会被写入,txtSource直到txtTarget失去焦点(即您关闭它).