我将一个 TextBox 绑定到 ViewModel。
我正在尝试使用:
string txt = vm.Example_Text;
与以下相同:
string txt = tbxExample.Text;
问题
在 TextBox 中键入可以正常工作。
但是在输入之后,如果我点击出 TextBox 并点击另一个控件,程序就会崩溃并抛出错误Make sure you do not have an infinite loop or infinite recursion.
这是一个只有 TextBox 和 ViewModel 的源文件
https://www.dropbox.com/s/n1hfnkmdckpwtms/TextBoxMVVM.zip?dl=0
XAML
<TextBox x:Name="tbxExample"
Text="{Binding Example_Text, Mode=TwoWay}"
IsEnabled="{Binding Example_IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Padding="1, 1, 0, 0"
Margin="0,2,0,0"
Width="100"
Height="22"
MaxLines="1" />
视图模型
public string _Example_Text;
public string Example_Text
{
get { return _Example_Text; }
set
{
if (_Example_Text == value)
{
return;
}
Example_Text = value;
OnPropertyChanged("Example_Text");
}
}
调试中的错误似乎突出显示set { };