INotifyPropertyChanging
के बारे में कुछ ध्यान में रखना है कि आप को होने से होने वाले परिवर्तन को रोक नहीं सकते हैं। यह आपको केवल यह रिकॉर्ड करने की अनुमति देता है कि परिवर्तन हुआ।
मैं इसे परिवर्तन ट्रैकिंग के लिए खान के ढांचे में उपयोग करता हूं, लेकिन यह परिवर्तनों को रोकने के लिए उचित तरीका नहीं है। इस बिंदु पर
delegate void AcceptPendingChangeHandler(
object sender,
AcceptPendingChangeEventArgs e);
interface IAcceptPendingChange
{
AcceptPendingChangeHandler PendingChange;
}
class AcceptPendingChangeEventArgs : EventArgs
{
public string PropertyName { get; private set; }
public object NewValue { get; private set; }
public bool CancelPendingChange { get; set; }
// flesh this puppy out
}
class ViewModelBase : IAcceptPendingChange, ...
{
protected virtual bool RaiseAcceptPendingChange(
string propertyName,
object newValue)
{
var e = new AcceptPendingChangeEventArgs(propertyName, newValue)
var handler = this.PendingChange;
if (null != handler)
{
handler(this, e);
}
return !e.CancelPendingChange;
}
}
आप अपना दृश्य मॉडल के लिए सम्मेलन द्वारा इसे जोड़ने की आवश्यकता होगी::
आप एक कस्टम इंटरफेस/घटना जोड़ी के साथ अपने ViewModelBase
का विस्तार कर सकता है
class SomeViewModel : ViewModelBase
{
public string Foo
{
get { return this.foo; }
set
{
if (this.RaiseAcceptPendingChange("Foo", value))
{
this.RaiseNotifyPropertyChanging("Foo");
this.foo = value;
this.RaiseNotifyPropretyChanged("Foo");
}
}
}
}
आप यहां क्या हासिल करना चाहते हैं? यह जानने के लिए उपयोग का मामला क्या है कि संपत्ति कब * बदलने के बारे में है? – ChrisF
उपयोगकर्ता को सत्यापित करने के लिए "क्या आप निश्चित हैं?" कुछ बदलावों के लिए ... हम यह सुनिश्चित करना चाहते हैं कि व्यवस्थापक का मतलब उपयोगकर्ता के उपयोगकर्ता नाम/लॉगिन को बदलना है और उन्होंने गलती से क्षेत्र को अपडेट नहीं किया है। – michael