Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Using a theme messes with control alignment
3 replies. Latest Post by jasonxz on November 6, 2009.
(0)
ivanpelly
Member
18 points
27 Posts
07-22-2009 1:00 PM |
I have a page which includes a DataGrid within a TabItem of a TabControl. The horizontal and vertical alignment of the datagrid are set to "Stretch", which works (i.e. the datagrid fills the tabitem, regardless of the number of rows in the datagrid) when no theme is applied. If, however, I wrap the LayoutRoot grid of the page with expressionDark:ExpressionDarkTheme /expressionDark:ExpressionDarkTheme tags, the datagrid is now vertically centered in the tabitem, showing just the rows that have data, and the datagrid no longer fills the TabItem. Remove the theme tags, and it works properly, as before.
JustinAngel
Contributor
4415 points
596 Posts
07-24-2009 8:28 PM |
Hi Ivan,
The Themes apply Alignment to multiple controls, including TabControl, TabItem and DataGrid.
Here's the TabItem Expression Dark Alignment: (copied from the XAML we ship)
<Style TargetType="controls:TabItem">
....
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
It sounds like the default alignment for TabItem not the values you're interested in. You've got 2 options at this point:
1. Setting TabItem Alignment in your page to whatever value you'd like.
<controls:TabItem HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
2. Using ImplicitStyleManager to apply "System.Windows.Controls.Theming.ExpressionDark.xaml" on your page and editing the Theme XAML directly.
Sincerely,
07-28-2009 11:14 AM |
Hi Justin - Thanks for the explanation - much appreciated. I guess the next (and perhaps rhetorical) question is, why would a theme do that? It seems that the benefit of a theme is to quickly apply a professional-looking aesthetic to a page (or control, etc.)... if the theme goes so far as to alter the layout, well, it's not so appealing to have to go in and fix all the things the theme messed up. Am I missing something? Cheers!
jasonxz
Participant
1752 points
530 Posts
11-06-2009 5:22 PM |
Justin, How do I get the Uri for "System.Windows.Controls.Theming.ExpressionDark.xaml". If I use that string to create a Uri & pass it to ImplicitStyleManager.SetResourceDictionaryUri(), it'll throw an exception stating that it can't find a Resource Dictionary. It would be nice if the Theme class had a Uri property that would expose the Uri of the xaml file that defines the theme. Also, when I put a TabControl in the ExpressionDarkTheme, it doesn't apply the theme to the TabItem headers.
Justin,
How do I get the Uri for "System.Windows.Controls.Theming.ExpressionDark.xaml". If I use that string to create a Uri & pass it to ImplicitStyleManager.SetResourceDictionaryUri(), it'll throw an exception stating that it can't find a Resource Dictionary.
It would be nice if the Theme class had a Uri property that would expose the Uri of the xaml file that defines the theme.
Also, when I put a TabControl in the ExpressionDarkTheme, it doesn't apply the theme to the TabItem headers.