Applying settings

May 6, 2009 at 3:29 PM
When I use a theme, how would I add to those settings?

For instance if I want some buttons of a certain width in a stack panel, I would normally do something like:

<

 

StackPanel xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 

 

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">

 

 

<StackPanel Margin="0,0,0,8" Orientation="Horizontal">

 

 

<StackPanel.Resources>

 

 

<Style TargetType="Button">

 

 

<Setter Property="Width" Value="50"/>

 

 

</Style>

 

 

</StackPanel.Resources>

 

 

<Button>Filter</Button>

 

 

<Button>Add</Button>

 

 

<Button>View</Button>

 

 

<Button>Edit</Button>

 

 

<Button>Delete</Button>

 

 

<Button>Close</Button>

 

 

</StackPanel>

 

 

But if I do that, the theme won't apply to those buttons.  Is there a way to get settings to be cumulative?  i.e. The Style settings overridden with my specific settings?

 

May 7, 2009 at 6:00 PM
Edited May 7, 2009 at 6:00 PM
You have to add the BasedOn attribute to your styles, so they inherit the theme style like:

    <Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource {x:Type ComboBox}}">
        <Setter Property="Margin" Value="5"/>
    </Style>
May 8, 2009 at 1:06 AM
Edited May 8, 2009 at 1:57 AM

I've got this, which I see other people say should inherit styles, bottom line is it's not.  I'm applying the theme with:

Windows.Application.Current.Resources = XamlReader.Load(xml.CreateReader())

If that makes any difference.  XML is an XElement with the theme in it.  I happen to be pulling from a resource.

 <StackPanel Orientation="Horizontal">
  <StackPanel.Resources>
    <Style BasedOn="{StaticResource {x:Type Button}}" TargetType="Button">
      <Setter Property="Width" Value="80"/>
      <Setter Property="Margin" Value="0,0,8,0"/>
    </Style>
  </StackPanel.Resources>
  <Button Height="23" Name="Button1" >Button</Button>
  <Button Height="23" Name="Button2" >Button</Button>
  <Button Height="23" Name="Button3" >Button</Button>
</StackPanel>

I also tried you're original suggestion:

<Style BasedOn="{StaticResource {x:Type Button}}" TargetType="{x:Type Button}">

Which didn't seem to make any difference.

 

Any help is really appreciated.  It's driving me nuts lol.

May 8, 2009 at 2:32 PM

I think your problem might be in how you're loading the skin, Im using the following in the App.xaml.cs:

 

            // Load application skin

            var resources = (ResourceDictionary) Application.LoadComponent(new Uri("../Skins/default.xaml", UriKind.RelativeOrAbsolute));

            Current.Resources = resources;

This loads the skin globally for the application, all other controls then inherit the styles using based on.

I've also tested this injecting views using prism and it works like a charm. Let me know.