My code currently looks like this:
private Foo myFoo;
public Foo CurrentFoo
{
get { return myFoo; }
set { SetFoo(value); }
}
private void SetFoo(Foo newFoo)
{
// Do stuff
// Here be dragons
myFoo = newFoo;
}
To be able to bind it in XAML/WPF I need to turn Foo
into a dependency property:
public static DependencyProperty CurrentFooProperty =
DependencyProperty.Register("CurrentFoo", typeof(Foo),
typeof(FooHandler), new PropertyMetadata(false));
public Foo CurrentFoo
{
get { return (Foo)GetValue(CurrentFooProperty); }
set { SetValue(CurrentFooProperty, value); }
}
Ive heard that you shouldnt do magic inside the actual C# property set {}, since it might not be called but the value is written directly to the dependency property. If this is false, let me know, it seems like the most obvious and simple route to take.
I know I can add a validation function to the dependency property but I assume that it shouldnt be used for this? I need to communicate the change to legacy systems that cannot yet be bound in XAML.
Whats the best way to approach this problem?