私はWPFを初めて使用し、WinFormsのバックグラウンドを持っており、バインディングとイベント処理についてかなり基本的な質問があります。
Presentation責任の分離を維持するために、ビジネスオブジェクトのUIデータ部分を保持するだけのオブジェクトがたくさんありますDependency Properties。ビジネスオブジェクトには同様のデータが含まれていますが、データ型が異なる場合があるため、Presentationオブジェクトは表示目的。だから何かのような
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
}
}
のプロパティはMyPresentation、さまざまなコントロールにバインドされたデータであり、 Triggersなどを使用してプレゼンテーションの依存関係プロパティを変更します。これにより、OnPropertyChangedイベントでビジネスオブジェクトが変更されます。
私が持っている質問は、私が正しい方法でバインディングを使用しているかどうかです。通常(Winformsでは)クリックイベントなどを使用してビジネスオブジェクト(またはそれらのプレゼンテーションバージョン)の値を変更していましたが、これらの種類のイベントとその種類のイベント処理は、、、およびイベントを使用できるようになったためBinding、不要に思えます。TriggerOnPropertyChanged
私は何かが足りないのですか?