Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Problems with ImplicitStyleManager on ListBox in TabControl (SL2)
9 replies. Latest Post by Rob263 on July 13, 2009.
(0)
Rob263
Member
35 points
22 Posts
06-18-2009 10:14 PM |
Hi,
I'm having major problems getting a theme applied properly to a control containing a listbox.
I have a simple test project which shows the incorrect/unexpected behaviour:
The problem is pretty obvious - in the second case, there's no content for the list box items. In the third case, when the theme is applied using code-behind, it works for a ListBox in the control, but not for a ListBox inside a TabControl inside the control.
You can download the source of the test project here: http://www.siklos.ca/ismbug/IsmListboxInTabcontrolBug.zip
[Edit: If you replace the TabControl/TabItem with a plain old ContentControl, you see the same result]
Here's the XAML for the page:
1 <UserControl x:Class="IsmListboxInTabcontrolBug.Page"2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"4 xmlns:theming="clr-namespace:System.Windows.Controls.Theming;assembly=System.Windows.Controls.Theming.Toolkit"5 xmlns:local="clr-namespace:IsmListboxInTabcontrolBug;assembly=IsmListboxInTabcontrolBug">6 <Grid x:Name="LayoutRoot"7 Background="White">8 9 <StackPanel>10 <StackPanel>11 <TextBlock>Unstyled:</TextBlock>12 <local:AllControls Grid.Row="2" />13 </StackPanel>14 15 <StackPanel>16 <TextBlock>Styled using ISM in XAML:</TextBlock>17 <local:AllControls theming:ImplicitStyleManager.ApplyMode="Auto"18 theming:ImplicitStyleManager.ResourceDictionaryUri="/IsmListboxInTabcontrolBug;component/System.Windows.Controls.Theming.ExpressionDark.xaml" />19 </StackPanel>20 21 <StackPanel>22 <TextBlock>Styled using ISM in code-behind:</TextBlock>23 <local:AllControls x:Name="allControls" />24 </StackPanel>25 26 </StackPanel>27 </Grid>28 </UserControl>29
meykih
Participant
876 points
213 Posts
06-19-2009 6:53 AM |
Third case I can explain to you: your listbox is inside a tabcontrol which means a user control is embedded inside another user control. And that won't work directly (don't know the reason but it doesn't work). Each embedded user control needs its own ISM...
06-19-2009 9:05 AM |
Thanks for your response meykih - however I disagree with your statements.
First, ListBox and TabControl are not UserControls - they're ItemsControls.
Second, there's very interesting behaviour if I comment the style for "ListBox" out of the theme.xaml file. In such a case, the items get shown properly (according to the style for ListBoxItem defined in the theme). However, this isn't exactly the greatest solution, since the ListBox itself is now un-themed.
Here's what it looks like if I comment the style for ListBox out of the theme: http://www.siklos.ca/ismbug/ism_bug_noListBoxStyle.png
Mog Lian...
All-Star
15874 points
1,541 Posts
06-24-2009 12:43 AM |
I open your project in silverlight 3 and update System.Windows.Controls.Theming.Toolkit.dll reference (silverlight3 March 2009).
the result is correct.
06-24-2009 9:38 AM |
Hi Mog,
Now I'm really confused. I just set up a brand new virtual machine with VS2008 and the latest Silverlight 3 Beta and Silverlight 3 toolkit (just downloaded). Silverlight 2 was never installed on the machine.
When I run the project (with updated references to Silverlight 3 libraries), I get the same result as before.
Any idea what could be different on your machine that allowed you to get it working?
Thanks,
Rob.
jahusain
342 points
52 Posts
06-24-2009 10:28 AM |
Unfortunately it is possible you are being affected by one of three known issues.
1. The public developer beta of Silverlight has a known issue with styling ItemsControls. In certain specific situations the items within don't get styled correctly.
2. You should be using the System.Windows.Controls.Theming.Toolkit.dll from the Silverlight 2 drop. The reason is that the one in Silverlight 3 has a bug which may be confusing things. There is no difference between the two versions except for this bug.
3. ISM has a known issue with TabControl which is most likely responsible for this issue.
Try this workaround. Put a Grid at the root of the Tab Item. Then copy and paste the ListBox and ListBoxItem styles from the theme XAML into the Resources of the Grid.
Let me know if that solves the problem.
06-24-2009 1:00 PM |
Thanks for your response jahusain, unfortunately, I was unable to succeed.
I tried the SL2 Theming.Toolkit DLL, but it didn't make any difference.
As for your workaround, I am sure this will work, however it really defeats the purpose of the ISM, since I need to be able to apply styles dynamically (depending on which theme the user has chosen), so hardcoded styles will not deal with this case.
As I mentioned before, it's not only the TabControl that causes problems. If I put my control inside a ContentControl, it also fails in the same way.
06-24-2009 2:37 PM |
To me, it's looking more and more like a Silverlight bug.
Basically, what I'm seeing is this:
1) when I apply ISM to a control with a listbox inside, it works fine.
2) when I apply ISM to a control with a ContentControl containing a ListBox, somehow, the Content of all the ListBoxItem objects in the ListBox is cleared.
06-24-2009 9:29 PM |
sorry for misdirect you, I tested your project on latest siverlight build, not v3.0.40224.0
this may be an fixed bug in silverlight.
07-13-2009 2:35 PM |
Happy to say that this is indeed fixed in SL3 RTW
Thanks for all your help.