c# - Setting DataGridRow RowDetails visibility after toggling between TabItems -


i have tabcontrol, in each tabitem there datagrid. each datagridrow has button on datagridrowheader, expands , collapses rowdetails.

as use row details expansion functionality, have set virtualizingpanel scrollunit pixel, scrolling bit more natural.

the program captures rows have been expanded in observablecollection<int> holds row index expand.

when toggle new tabitem , original tabitem, loses rows have been expanded.

upon datacontext being changed, i'd use observablecollection reset expanded rows. have tried in datagrid datacontextchanged event.

public class datagridbehaviors : behavior<datagrid>{     protected override void onattached(){         base.onattached();         this.associatedobject.datacontextchanged += datagrid_datacontextchanged;     }      protected override void ondetaching(){         this.associatedobject.datacontextchanged -= datagrid_datacontextchanged;         base.ondetaching();     }      private void datagrid_datacontextchanged(object sender, dependencypropertychangedeventargs e){         modulegeometry oldmodulegeometry = (modulegeometry)e.oldvalue;         modulegeometry newmodulegeometry = (modulegeometry)e.newvalue;          task.factory.startnew(() => {             performrowexpansions(newmodulegeometry);         });          scrollviewer scrollviewer = getvisualchild<scrollviewer>(this.associatedobject);         if (scrollviewer != null){             /*              * stuff              */         }     }      private void performrowexpansions(modulegeometry newmodulegeometry){         observablecollection<int> tempexpandedindexes = new observablecollection<int>(newmodulegeometry.expandedindexes);         newmodulegeometry.expandedindexes = new observablecollection<int>();          if (this.dispatcher.checkaccess()){             foreach (int index in tempexpandedindexes)             {                 datagridrow row = this.associatedobject.itemcontainergenerator.containerfromindex(index) datagridrow;                 row.detailsvisibility = visibility.visible;             }         }         else{             this.dispatcher.invoke(new action(() =>{                 foreach (int index in tempexpandedindexes){                     datagridrow row = this.associatedobject.itemcontainergenerator.containerfromindex(index) datagridrow;                     row.detailsvisibility = visibility.visible;                 }             }));         }     }      private static t getvisualchild<t>(dependencyobject parent) t : visual{         t child = default(t);          int numvisuals = visualtreehelper.getchildrencount(parent);         (int = 0; < numvisuals; i++){             visual v = (visual)visualtreehelper.getchild(parent, i);             child = v t;             if (child == null)                 child = getvisualchild<t>(v);             if (child != null)                 break;         }         return child;     } } 

however, doesn't doing on rows not in virtualizingpanel.

how can accomplish this?
should expand virtualized rows?
should datagrid scrollviewer manipulated programmatically well? how can account rows not visible in scrollviewer?
there object, other datagridrow should setting rowdetails visibility to?

there no datagridrow containers rows not in virtualizingpanel. that's how virtualization works.

if want persist information between tab switches, should store data persisted in view models. example bind button in datagridrowheader command adds , removes indexes collection in underlying data class, i.e. datacontext of parent datagridrow, tabitem or tabcontrol.

trying iterate through visual datagridrow containers won't work unless disable ui virtualization. , may of course lead performance issues.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -