Is there a possibility to update a textbox without implementation of the INotifyPropertyChanged
interface,
e.g. with a trigger or an event from my ViewModel?
My example Code
UserControl:
<StackPanel VerticalAlignment="Center">
<TextBox Text="{Binding Model.ExampleClass.MyProperty, Mode=TwoWay}" Height="20" Width="400"/>
<TextBox Text="{Binding Model.TestProperty, Mode=TwoWay}" Height="20" Width="400"/>
</StackPanel>
<Button Command="{Binding ButtonClickCommand}" Grid.Row="1" Content="Click" Height="40"/>
ViewModel:
private Model _model = new Model();
public Model Model
{
get { return _model; }
set { SetProperty(ref _model, value); }
}
public ICommand ButtonClickCommand { get; private set; }
public ViewModel()
{
ButtonClickCommand = new RelayCommand(ButtonClickExecute, ButtonClickCanExecute);
}
#region ICommand
private bool ButtonClickCanExecute(object obj)
{
return true;
}
private void ButtonClickExecute(object obj)
{
Model.ExampleClass.MyProperty = 50;
Model.TestProperty = 50;
}
#endregion
Model:
private ExampleClass _exampleClass = new ExampleClass() { MyProperty = 30};
private int _testProperty = 30;
public ExampleClass ExampleClass
{
get { return _exampleClass; }
set { SetProperty(ref _exampleClass, value); }
}
public int TestProperty
{
get { return _testProperty; }
set { SetProperty(ref _testProperty, value); }
}
ExampleClass (cannot be changed):
public class ExampleClass
{
public int MyProperty { get; set; }
}
My Problem
I want to update my property MyProperty
in my ExampleClass
by a button click (without implementation of INotifyPropertyChanged
or that I need to make any other changes to the class).