I'm new to WPF and come from a WinForms background and have a fairly basic question about binding vs event handling.
To try and maintain some separation of responsibility I've have a bunch of presentation objects which simply have dependency properties to hold the UI data parts of a business object, the business object contains similar data but the data types are occationally different so that the Presenation object is correct for display purposes. So something like
public class MyPresentation
{
// bunch of dependency properties
public bool MyProperty
{
get { return (bool)GetValue(MyPropertyProperty); }
set { SetValue(MyPropertyProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(bool), typeof(MyPresentationObject), new UIPropertyMetadata(false, MyPresentationObject.MyPropertyPropertyChanged));
MyBusinessObject RelatedBusinessObject { get; set;}
public MyPresentation(MyBusinessObject businessObejct)
{
this.RelatedBusinessObject = businessObject;
}
public static void MyPropertyPropertyChanged()
{
// Do some stuff to related business objects
}
}
The properties of MyPresentation are then data bound to various controls and I use triggers etc to change presentation dependency properties which causes business object changes in the OnPropertyChanged event. The question I have is am I using binding in the correct fashion? Normally (in Winforms) i'd have used click events etc to change my business objects (or the presentation versions of them) values but those sort of events and that sort of event handling seems superfluous now that you can use binding, triggers and OnPropertyChanged events.
Am I missing something?