Theme inheritance

2 posts, 0 answers
  1. Murray
    Murray avatar
    121 posts
    Member since:
    Aug 2010

    Posted 12 Jan 2012 Link to this post

    Hi

    We are using your Expression_Dark theme (customers love it!) and to apply the theme to non-Telerik controls I handle it in ResourceDictionaries like this...

    <Style TargetType="TextBox" telerik:StyleManager.BasedOn="Expression_Dark">

    This works great, however on certain forms we might want to set specific properties of a TextBox like margins.

    <UserControl.Resources>
            <Style TargetType="TextBox">
                <Setter Property="Margin" Value="5"/>
            </Style>
        </UserControl.Resources>


    If we use an inline Usercontrol.Resources declaration, the declaration completely ignores anything set in the ResourceDictionary!

    Any idea on how to get both?



  2. Murray
    Murray avatar
    121 posts
    Member since:
    Aug 2010

    Posted 13 Jan 2012 Link to this post

    Found the answer.

    In your ResourceDictionary.xaml:
    Add a Key to what you originally wanted to be global.
    <Style TargetType="TextBox" telerik:StyleManager.BasedOn="Expression_Dark"  x:Key="Main">
            <Setter Property="AllowDrop" Value="true"/>
            <Setter Property="IsEnabled" Value="true"/>
            <Setter Property="AcceptsReturn" Value="false"/>
            <Setter Property="TextWrapping" Value="NoWrap"/>
            <Setter Property="IsReadOnly" Value="false"/>
        </Style>

    Create an empty global style and base it on the key.
    <Style TargetType="TextBox" BasedOn="{StaticResource Main}">
     </Style>

    This will still use everything in the keyed style globally.

    Then on the page.xaml you want to add additional styles globally to just that page (like Margins) do this:
    <UserControl.Resources>
            <Style TargetType="TextBox" BasedOn="{StaticResource Main}">
                <Setter Property="Margin" Value="80" />
            </Style>
        </UserControl.Resources>

    This will give you everything in the ResourceDictionary PLUS stuff declared locally!

  3. DevCraft banner
Back to Top