c# - In a panel, how can you add multiple visual elements per logical child? -


we have custom panel subclass we're each logical child that's added it, want add 2 additional visual children. if logical child removed, want remove 2 related visuals. internally map logical element 2 additional visuals keep track of of this.

however, can't seem break one-to-one relationship between children collection , actual visual children in panel's implementation.

here's our first attempt, we're not getting anywhere this. created custom subclass of uielementcollection exposes logicalchildren collection. while display proper items in panel, panel's children property returns visuals, not our logicalchildren collection , can't override children.

we attempted use [contentproperty] attribute on class point different property, fixed xaml, still have children problem above.

we considered newing on it, user cast down panel , @ guts.

what want panel's children property hold logical things we've added externally. 2 additional visual items don't want user have access (short of reflection or explicitly waling visual tree is.)

to recap, if this...

<trivisualpanel>     <textbox />     <textbox />     <textbox /> </trivisualpanel>    

we want logical tree (so if user panel.children.count, three)...

trivisualpanel  - textbox  - textbox  - textbox 

...and visual tree (used in measure , arrange overrides) this...

trivisualpanel  - textbox  - textblock <- added dynamically  - textblock <- added dynamically  - textbox  - textblock <- added dynamically  - textblock <- added dynamically  - textbox  - textblock <- added dynamically  - textblock <- added dynamically 

here's our (mess of) code...

public class trivisualpanel : panel {     protected override uielementcollection createuielementcollection(frameworkelement logicalparent)     {         return new trivisualuielementcollection(this, logicalparent);     }        }  public class trivisualuielementcollection : uielementcollection {      public trivisualuielementcollection(uielement visualparent, frameworkelement logicalparent)     : base(visualparent, logicalparent)     {         logicalchildren = new collection<uielement>();     }      private collection<uielement> logicalchildren;      private void createtrivisualsforlogicalelement(uielement logicalelement, int index)     {         [faux code create 3 visuals here...]         base.insert(index, newvisuala);         base.insert(index, newvisualb);         base.insert(index,newvisualc);          maplogicaltovisuals(logicalelement, newvisuala, newvisualb, newvisualc);        logicalchildren.add(logicalelement);     }      public override int add(uielement element)     {         createtrivisualsforlogicalelement(element, count);     }      public override void insert(int index, uielement element)     {         createtrivisualsforlogicalelement(element, index);     }      public override void remove(uielement element)     public override void removeat(int index)     public override void removeat(int index)     {         bla bla...     }  } 


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -