Skip to main content

Microsoft Silverlight

Answered Question Using a theme messes with control alignmentRSS Feed

(0)

ivanpelly
ivanpelly

Member

Member

18 points

27 Posts

Using a theme messes with control alignment

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.

Ivan Pelly

JustinAngel
JustinAngel

Contributor

Contributor

4415 points

596 Posts

Answered Question

Re: Using a theme messes with control alignment

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,

--
Justin Angel,
Blog @ http://silverlight.net/blogs/JustinAngel
Twitter @ http://twitter.com/JustinAngel

ivanpelly
ivanpelly

Member

Member

18 points

27 Posts

Re: Re: Using a theme messes with control alignment

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!

Ivan Pelly

jasonxz
jasonxz

Participant

Participant

1752 points

530 Posts

Re: Using a theme messes with control alignment

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.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities