Monday, August 27, 2012

How can I get an implicit style for Combobox that doesn't screw up my theme?

How can I get an implicit style for Combobox that doesn't screw up my theme?

I have had these comboboxes that have 1,000+ items.  (I know I shouldn't do that, but I want to do it anyway Smile )
It is REEEALLLY SLLLLOOOWWW to drop down.  Actually, it is ridiculously slow.  But if I add this in the xaml as part of the Combobox:
                     <ComboBox.ItemsPanel>                          <ItemsPanelTemplate>                             <VirtualizingStackPanel/>                          </ItemsPanelTemplate>                       </ComboBox.ItemsPanel>  
it works astoundingly well.
BUT, I have my whole app themed and when I try to use an implicit style so that ALL my comboboxes are virtualized, I lose the theming on the combobox.  This happens when I do something like this:
   <Style x:Key="mystyle" TargetType="ComboBox">        <Setter Property="ItemsPanel">           <Setter.Value>              <ItemsPanelTemplate>                 <VirtualizingStackPanel/>              </ItemsPanelTemplate>           </Setter.Value>        </Setter>     </Style>  
And try to use an explicit style.  And I don't think I could even get the Implicit style to work at all because of the theming.
So is there a way to get the Virtualizing for all the comboboxes without having to dig into the internals of the theme and/or build my own copy of the theme?


Answers & Comments...

Answer: 1
Hi,
How about wrapping a ComboBox in a UserControl and set ItemsPanelTemplate in XAML (not by defining style). Then use the UserControl for reuse purpose?


Answer: 2
That might work.  Now I realize I have a bigger problem.  When the VirtualizingStackPanel is used and an item in the combobox is Selected, the popup doesn't scroll right.  It only has about twice the number of items in the displayed list that can be scrolled.
I presume this bug is why the combobox never got a VirtualizingStackPanel in the first place.
REALLY wish I could use this VirtualizingStackPanel as performance sucks without it.


Answer: 3
Hi,
Could you post a demo that can reproduce this issue? You can upload the project to:
https://skydrive.live.com/
and post download link here


Answer: 4
I won't be able to create something for you for a few days.  But it SHOULD be easy to reproduce.  Just make code that does a loop and creates say 1000 strings, like abc1, abc2, abc3, etc.  Then set the ItemsSource of the combobox to that.  Then select one of the items say around item 500.  Then try to scroll up and down and see how far the scroller thumb lets you move.
Oh, and even if I could make the example, you couldn't compile it most likely.  I don't like C# and use Delphi Prism.


Answer: 5
I decided it was so easy I'd do one quick.  But the one I made doesn't fail.  So there must be something special about the one that fails.  I'll have to work on making something later.




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog