Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Binding vs Event Handling
    primarykey
    data
    text
    <p>I'm new to WPF and come from a WinForms background and have a fairly basic question about binding vs event handling. </p> <p>To try and maintain some separation of responsibility I've have a bunch of <code>Presentation</code> objects which simply have <code>Dependency Properties</code> 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 <code>Presentation</code> object is correct for display purposes. So something like</p> <pre><code>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 } } </code></pre> <p>The properties of <code>MyPresentation</code> are then data bound to various controls and I use <code>Trigger</code>s etc to change presentation dependency properties which causes business object changes in the <code>OnPropertyChanged</code> event</p> <p>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 <code>Binding</code>, <code>Trigger</code>s and <code>OnPropertyChanged</code> events.</p> <p>Am I missing something?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload