我在FileWindow.xaml中有一个TextBox:
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="233,230,0,0" TextWrapping="Wrap" Text="{Binding FileName}" VerticalAlignment="Top" Width="120"/>
Run Code Online (Sandbox Code Playgroud)
在ViewModel.cs中:
public String FileName
{
get { return _model.filename; }
set
{
if (value != _model.filename)
{
_model.filename = value;
OnPropertyChanged();
}
}
}
Run Code Online (Sandbox Code Playgroud)
在Model.cs中:
private String _filename = "example.txt";
public String filename { get { return _filename; } set { _filename = value; } }
Run Code Online (Sandbox Code Playgroud)
我希望每次输入TextBox时,Model.cs中的_filename都会更新.
TextBox中的默认文本是example.txt,但如果我更改它,Model.cs中的_filename不会更改.我究竟做错了什么?