c# - Using a custom ListBoxItem definition in ListBox for performance analysis -


i trying analyze performance of code , better understand redraw behavior of wpf canvas using itemspanel inside listbox. end have defined custom class mylistboxitem derives listboxitem (see code below).

unfortunately cannot figure out how use class inside listbox. tried binding list of mylistboxitem instances listbox.items in xaml items="{binding path=listboxitemslist}", error

'items' property read-only , cannot set markup.

is there way achieve this? or perhaps there other alternative achieve doing? (i.e. analysis of redraw-behavior)

definition of mylistboxitem:

public class mylistboxitem : listboxitem {     public mylistboxitem(objectviewmodel vm)     {         this.datacontext = vm;     }      size? arrangeresult;      protected override size measureoverride(size constraint)     {         var vm = (this.datacontext objectviewmodel);         if (vm != null)         {             debug.writeline("for objectviewmodel " + vm.name + ":");         }         arrangeresult = null;         system.console.writeline("measureoverride called " + this.name + ".");         return base.measureoverride(constraint);     }      protected override system.windows.size arrangeoverride(system.windows.size arrangesize)     {         if (!arrangeresult.hasvalue)         {             system.console.writeline("arrangeoverride called " + this.name + ".");             // arrange work here             arrangeresult = base.arrangeoverride(arrangesize);         }          return arrangeresult.value;     }      protected override void onrender(system.windows.media.drawingcontext dc)     {         system.console.writeline("onrender called " + this.name + ".");         base.onrender(dc);     } } 

you can create derived listbox overrides getcontainerforitemoverride , isitemitsowncontaineroverride methods return custom listboxitem:

public class mylistboxitem : listboxitem { }  public class mylistbox : listbox {     protected override dependencyobject getcontainerforitemoverride()     {         return new mylistboxitem();     }      protected override bool isitemitsowncontaineroverride(object item)     {         return item mylistboxitem;     } } 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -