Dear Support Team,
I'm working with a PocoViewModel. There a property is defined using an own class. In the PocoViewModel a OnChanged Method is implemented to the own class property but the OnChanged Method is not called even when a bound Textbox in XAML updates correctly.
The class:
C#public class SubClass:BindableBase
{
public virtual string Text {
get { return GetValue<string>(); }
set { SetValue(value); }
}
}
Snippet of the PocoViewModel:
C#public virtual SubClass TheSubClass { get; set; }
...
public void OnTheSubClassChanged()
{
InfoText += Environment.NewLine + "OnTheSubClassChanged method done";
}
You can find a demonstration project attached.
A workaround I found is to inscribe to the PropertyChanged Event of the subclass and place my code in the event handler:
C#[POCOViewModel]
public class MainViewModel
{
public virtual SubClass TheSubClass { get; set; }
public virtual string InfoText { get; set; }
private int ChangeCnt = 0;
public void ChangeText()
{
ChangeCnt++;
TheSubClass.Text = "Text changed by command, change No " + ChangeCnt.ToString();
InfoText += Environment.NewLine + "Command ChangeText done!";
}
public void OnTheSubClassChanged()
{
InfoText += Environment.NewLine + "OnTheSubClassChanged called";
}
private void SubClassContentChanged(object sender, EventArgs e)
{
if (sender == null)
return;
InfoText += Environment.NewLine + "SubClassContentChanged called";
}
#region poco constructor
protected MainViewModel()
{
TheSubClass = new SubClass();
TheSubClass.Text = "Start Text";
TheSubClass.PropertyChanged += SubClassContentChanged;
}
public static MainViewModel Create()
{
return ViewModelSource.Create(() => new MainViewModel());
}
#endregion
}
Why is the OnXXXChanged method not called even the class has BindableBase implemented?
Regards
Martin