c# - ListBox in WPF while using ItemContainerGenerator returns null -
i have listbox in xaml, few checkbox , filter button. application generates loads of logs display in listbox. when have data in listbox, xaml user check\uncheck checkbox. based on data in listbox filtered when button clicked. depending on data want show different forecolor , background color on each item.
private void filterbutton_click ( object sender , routedeventargs e ) { //whenever filter button clicked, check checkbox status. whichever //checkbox on add checkbox name dictionary. read string listbox , extract particular keyword , match dictionary key. if //matches modify background , foreground color particualr //listbox items. problem here listbox items updated rest of them //unchaged. when debugged found itemcontainergenerator returns null other //items. ( int = 0 ; < listbox1.items.count ; i++ ) { listboxitem item1 = ( listboxitem )listbox1.itemcontainergenerator.containerfromindex(i); string recordtype; string [] contentarray; if ( item1 == null ) continue; if ( item1.content == "" ) continue; contentarray = item1.content.tostring().split( new char [] { ',' }, stringsplitoptions.removeemptyentries ); recordtype = contentarray [ 1 ]; if ( checkboxtype.containskey ( recordtype )) { //int code = recordtypetocolorcode [ recordtype ]; //item1.foreground = colorcodetoforecolor [ code ]; item1.foreground = brushes.darkcyan; item1.fontsize = 13; item1.background = brushes.lightgoldenrodyellow; } else { item1.foreground = brushes.lightgray; } } }
the issue seeing if suppose listbox has 1000 items 35-40 items updated. rest items same. debugged more code , found after number 35-40 items coming null why not able update items in listbox. have not turned on virtualization in code. there way can update items. appreciated. thinking if there issue itemcontainergenerator, displays items, virtualization turned off. newbie wpf please bare me if silly question.
please following diagram more clearl;y understand issue
Comments
Post a Comment