c# - How to update binding based on value being dirty? -
i've datagrid 5 columns. first 3 columns part of parent object , last 2 columns part of child object. i've username column 6th column.
when update first 3 columns of parent object, username reflects correctly. when update last 2 columns of child object, doesn't update username.
i've tried binding , doing logic in child object , before 'save' username updates correctly last 2 columns after save reverts previous username.
my question is, how keep updated username after save?
xaml:
<datagridtextcolumn header="updated by" isreadonly="true" binding="{binding childobject.updateduser, updatesourcetrigger=propertychanged}"/>
child object:
public string updateduser { { var parent = this.crawlparentfindtype<parentobject>(); if (column4isdirtybyvalue || column5isdirtybyvalue) return updatedbyusername; else return parent.updatedbyusername; } } public bool column4isdirtybyvalue { { return fieldmanager.isfielddirty(column4property); } } public bool column5isdirtybyvalue{ { return fieldmanager.isfielddirty(column5property); } } public string column4 { { return getproperty(column4property); } set { setproperty(column4property, value); onpropertychanged(x => x.updateduser); } } public string column5 { { return getproperty(column5property); } set { setproperty(column5property, value); onpropertychanged(x => x.updateduser); } }
why code complex? think reason in onpropertychanged(x => x.updateduser); call updateduser property changed, property doesn't have setter. code below should work you, imho:
private bool _updateduser; public bool updateduser { { return _updateduser; } set { this.setproperty(ref this._updateduser, value); } } private string _column5; public string column5 { { return _column5; } set { this.setproperty(ref this._column5, value); updatedusercheck(); } } private void updatedusercheck() { this.updateduser = // check here }
wiki
Comments
Post a Comment