I have a TextBox in FileWindow.xaml :
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="233,230,0,0" TextWrapping="Wrap" Text="{Binding FileName}" VerticalAlignment="Top" Width="120"/>
In ViewModel.cs:
public String FileName
{
get { return _model.filename; }
set
{
if (value != _model.filename)
{
_model.filename = value;
OnPropertyChanged();
}
}
}
In Model.cs:
private String _filename = "example.txt";
public String filename { get { return _filename; } set { _filename = value; } }
I want that every time I type in the TextBox, the _filename in Model.cs gets updated.
The default text in the TextBox is example.txt, but if I change it, the _filename in Model.cs doesn't change. What am I doing wrong?
Try to set the UpdateSourceTrigger
property of the binding to PropertyChanged
:
Text="{Binding FileName, UpdateSourceTrigger=PropertyChanged}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With