c# - Is a custom usercontrol created each time the datacontext changes? -
this more of general question... have user command i've written (usercontrol,not custom control). i'm using command in datagridcolumn provide lookup functionality..much this:
<datagridtemplate columnheader="company"> <datagridtemplatecolumn.celltemplate> <datatemplate> <lookupctl:lookupctl selectedcompany="{binding company, mode=twoway, updatesourcetrigger=propertychanged}" companychangedcommand="{binding datacontext.companychangedcmd, relativesource={relativesource ancestortype=datagrid}}"/> </datatemplate> </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn>
what i'm noticing whenever dataconext changes parent/containing control, constructor of lookupctl called. expected behavior? anyway prevent this? don't see why necessary...the single instance of command should able refresh datacontext think.
edit: googling not providing clear answers...but i've read, may datagrid that's issue. since command used in datagrid, each time grid's itemsource changes, destroy , recreate controls? can see sense in doing so..but not sure if reason i'm seeing. assuming is...is there way have datagrid reuse instances of usercontrol rather create new ones when datagrid's itemsource changes?
it appear reason usercontrols used datatemplate columns datagrid destroyed , recreated when itemsource datagrid changed. in case solution utilize normal grid given had 4 items in list used itemsource grid. not ideal , not solution n-item lists..but in case vastly improved performance since usercontrol performed intensive datbase lookups on initialization cache data.
c# .net wpf xaml
No comments:
Post a Comment