Unexpected Behaviour with WPF Datagrid Grouping with DateTimePicker control -
inside window, have simple datagrid control datetimepicker column, , textbox column. group rows inside datagrid month-year string derived datetimepicker. here xaml columns , grouping.....
<datagridtemplatecolumn header="date" width="100"> <datagridtemplatecolumn.celltemplate> <datatemplate> <xctk:datetimepicker isenabled="true" format="custom" formatstring="m/d/yyyy h:mm" value="{binding thedate, updatesourcetrigger=propertychanged, mode=twoway}"/> </datatemplate> </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn> <datagridtemplatecolumn header="text" width="150"> <datagridtemplatecolumn.celltemplate> <datatemplate> <textbox textwrapping="wrap" acceptsreturn="true" maxlines="2" verticalscrollbarvisibility="auto" maxlength="150" text="{binding thetext, updatesourcetrigger=lostfocus, mode=twoway}"></textbox> </datatemplate> </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn> <datagrid.groupstyle> <groupstyle> <groupstyle.headertemplate> <datatemplate> <stackpanel> <textblock text="{binding name}" fontweight="bold" padding="3"/> </stackpanel> </datatemplate> </groupstyle.headertemplate> </groupstyle> </datagrid.groupstyle>
i have simple class text string, , datetimepicker datetime, , string month-year create dynamically. here c# code class...
public datetime duedate { get; set; } public string task { get; set; } private string _monthyear; public string monthyear { { return duedate.month.tostring() + " - " + duedate.year.tostring(); } }
here initialization of grouping
mycollectionview = collectionviewsource.getdefaultview(myobservablecollectionlist); mycollectionview.groupdescriptions.add(new propertygroupdescription("monthyear")); mydatagrid.itemssource = mycollectionview; // in case, myobservablecollectionlist observable collection holds datagrid // rows. mycollectionview icollectionview object
everything working except 1 annoying piece of unexpected behavior. don't know if bug datetimepicker control extended wpf toolkit.
whenever change month or year on datetimepicker control , click on new row or different column in same row, row changed date not grouped remain inside old month-year date group until sort it. behavior fine if consistent however...
if change month or year on datetimepicker control, , tab through or click through same datetimepicker control (not changing anything), , click on new row, old row grouped new month - year category.
i'm not sure feel bug datetimepicker control it's calling sort of event when tab through control if don't change date. right i'm pretty confused, , wondering if has insight why happening.
*note** have tested , without inotifypropertychanged, have interface implemented, , behavior occurs , without implemented thought leave out simplicity sake.
any appreciated thank you!
i have fixed issue, caused uses of both _monthyear monthyear, guess whenever change date, there multiple calls change _monthyear. whatever reason, i'm assuming group description...
taskschedulecollection.groupdescriptions.add(new propertygroupdescription("monthyear"));
maybe mixed in valuechanged or similar event inside datetimepicker cause grouping re apply , new row groups created(i'm not 100% sure this).
i fixed issue removing _monthyear property unnecessary , keeping single monthyear property dependent on date.
public string monthyear { { return _date.month.tostring() + " - " + _date.year.tostring(); } }
the grouping reapplys whenever sort list collection, consistent behavior want.
Comments
Post a Comment