我有这个问题。当在 TextBox.text 的调试模式下观察到 0 时,WPF 文本框显示 1 而不是 0。这是文本框的 xmal 代码:
<TextBox Name="powerText" ToolTip="Enter the power value to go to" Width="100"
VerticalAlignment="Center" />
这是触发 TextBox 的 0 设置事件的按钮单击的 C# 代码:
private void Set_Click(object sender, RoutedEventArgs e)
{
if (powerText.Text.Length > 0)
{
try
{
((LiveImageViewModel)this.DataContext).PowerPosition =
Convert.ToInt32(powerText.Text);
}
catch (FormatException ex)
{
string str = ex.Message;
}
}
}
观察powerText.Text
到 0,但 UI 显示 1!我非常困惑为什么会发生这种情况,我应该如何纠正它?任何人的想法表示赞赏?非常感谢。