I have this WPF Window:
public Window1()
{
InitializeComponent();
this.Content = new TheForm();
}
Which loads this UserControl:
<UserControl x:Class="TestAutomaticUpdate82828.TheForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<DockPanel Margin="10" LastChildFill="True" VerticalAlignment="Top">
<TextBox DockPanel.Dock="Top" Text="{Binding InputText, UpdateSourceTrigger=PropertyChanged}" Height="25" Width="100" HorizontalAlignment="Left" Margin="0 0 0 3"/>
<TextBox DockPanel.Dock="Top" Text="{Binding OuputText}" Height="25" Width="100" HorizontalAlignment="Left" Margin="0 0 0 3"/>
</DockPanel>
</UserControl>
Which has this code-behind:
using System.Windows.Controls;
using System.Windows.Input;
using System.ComponentModel;
namespace TestAutomaticUpdate82828
{
public partial class TheForm : UserControl, INotifyPropertyChanged
{
#region ViewModelProperty: InputText
private string _inputText;
public string InputText
{
get
{
return _inputText;
}
set
{
_inputText = value;
OnPropertyChanged("InputText");
OutputText = "changed";
}
}
#endregion
#region ViewModelProperty: OutputText
private string _outputText;
public string OutputText
{
get
{
return _outputText;
}
set
{
_outputText = value;
OnPropertyChanged("OutputText");
}
}
#endregion
public TheForm()
{
InitializeComponent();
DataContext = this;
}
#region INotifiedProperty Block
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
}
However, when I run the application and type text into the InputText TextBox, I see that it steps into the Set property of InputText, but not further into the Set property of OutputText and hence, OutputText is not updated.
I had this working in a View / ViewModel structure, but why isn't it working in this code-behind scenario?