【发布时间】:2016-12-03 21:11:32
【问题描述】:
我正在学习 WPF 的教程系列。目前我在这一步http://www.wpf-tutorial.com/data-binding/responding-to-changes/
我遇到的问题是我希望文本框只在我离开文本框时更新值。但即使 无论是在里面还是在 TextBox 中,当我更改窗口大小时,该值也会更新。这不是我所期望的。我的错误在哪里?
这里是自己测试的简短代码:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<WrapPanel Orientation="Horizontal" Margin="0,10,0,0">
<TextBlock Text="Window dimensions: "/>
<TextBox Text="{Binding Width, UpdateSourceTrigger=LostFocus}" Width="50" />
<TextBlock Text=" x " />
<TextBox Text="{Binding Height, UpdateSourceTrigger=PropertyChanged}" Width="50"/>
</WrapPanel>
</Grid>
</Window>
【问题讨论】:
-
一切正常,请阅读更多关于LostFocus 的信息。因此,当您更改大小时,文本框会丢失
focus,而不是keyboard focus。
标签: c# .net wpf vb.net data-binding