c# - chart not updating when changing the value of displaymember -
i have modernui piechart binded observablecollection.
if change name of item not updating, if change value of on item updated properly(add/remove works fine).
chart xaml :
<chart:piechart grid.rowspan="2" style="{staticresource minimalchartstyle}" charttitle="minimal pie chart" chartsubtitle="chart fixed width , height" > <chart:piechart.series> <chart:chartseries seriestitle="categories" displaymember="categoryname" valuemember="categoryexpenselimit" itemssource="{binding path=cat}" /> </chart:piechart.series> </chart:piechart>
code add item: (this updates chart when adding item)
transactioncategorymodel category = new transactioncategorymodel() { thecategory = { categoryname = categoryname, categoryexpenselimit = (decimal)categoryexpenselimit }}; context.transactioncategories.add(category.thecategory); context.savechanges(); var obs = application.current.resources["categoryobs"] observablecollection<categoryviewmodel>; obs.add(new categoryviewmodel(category));
code edit item :(retrieve database , update update observable collection well)
var category = context.transactioncategories.where(i => i.categoryid == this.categoryid).first(); var tcategory = new transactioncategorymodel() { thecategory = category }; tcategory.thecategory.categoryid = (int)categoryid; tcategory.thecategory.categoryname = categoryname; tcategory.thecategory.categoryexpenselimit = (decimal)categoryexpenselimit; context.savechanges(); var obs = application.current.resources["categoryobs"] observablecollection<categoryviewmodel>; var x = obs.where(i => i.categoryid == this.categoryid).firstordefault(); categoryviewmodel cvm = new categoryviewmodel(tcategory); x = cvm;
with edit item. problem if edit , change name chart not update displaymember, if change expenselimit(this valuemember of chart) chart update properly. fact name not update happens chart. made datagrid in view , binded observablecollection , data grid updates when change name.
in viewmodel of chart :
private observablecollection<categoryviewmodel> cat; public observablecollection<categoryviewmodel> cat { { return cat; } set { cat = value; onpropertychanged("cat"); } }
and in constructor:
if (cat == null) cat = new observablecollection<categoryviewmodel>(); cat = application.current.resources["categoryobs"] observablecollection<categoryviewmodel>;
and when app starts : retrieve values
private void getcategories() { list<categoryviewmodel> categories = new list<categoryviewmodel>(); using( var context = new ents()) { foreach(var item in context.transactioncategories) { transactioncategorymodel tcm = new transactioncategorymodel() { thecategory = item }; categories.add(new categoryviewmodel(tcm)); } } observablecollection<categoryviewmodel> categories = new observablecollection<categoryviewmodel>(categories); application.current.resources.add("categoryobs", categories); }
..edit , change name chart not update displaymember
two things, observablecollection
signaler when items added or removed list. doesn't binding or processing of items edited.
secondly changes of individual items noticed, property bound needs signal change. signaling done when class it resides on implements inotifypropertychange
, calls onpropertychanged
method name.
so looking @ code, learning that, code
public observablecollection<categoryviewmodel> cat { { return cat; } set { cat = value; onpropertychanged("cat"); }}
only signals when new observable collection assigned. may helpful in situations, such swapping in , out of lists (i change combobox drop down selections) in case 1 trick pony useful chart , needed, chart doesn't care have observablecollection
. because 1 has purposefully subscribe observablecollection
events anything. frankly , should use list<categoryviewmodel>
instead.
chart not update displaymember
does property categoryname
on class categoryviewmodel
call propertychange because categoryviewmodel
implements inotifypropertychanged
?
note...even if does, charting tool may not subscribing change notification, because reporting tool , wasn't designed such. if case, may need wink whole categoryviewmodel
instance in , out (remove re-add it) make reporting chart control show change in name.
Comments
Post a Comment