Setting property through style for base class does not update property value for derived class RRS feed

  • Question

  • Hello,

    Can someone help me?  I have BaseClass(Derived from UserControl) which declares dependancy property BackGroundColor,

    All my inherited classes use this property to set the background for each of them.

    Now when I set my property using style in my theme file, using base class, this style is not applied for any of inherited class,

    But if I set style using derived class, Style is applied correctly. I have more than 10 derived classes, that may use this property.

    Can Someone tell me, how can I set the property in my theme file for base class and all the derived classes would get it?

    something like,

    <Style TargetType="BaseClass">

    <Setter Property="BaseClass.BackGroundBrush"

    Value="{StaticResource RPSBackGroundBrush}"/>



    Wednesday, July 1, 2009 9:47 PM


  • Hi,

    Silverlight 3 has new feature called "BasedOn", it can help you to remove style redundancy.

    sample xaml 

        <Grid x:Name="LayoutRoot" Background="White">
                <Style TargetType="FrameworkElement" x:Name="fe_style">
                    <Setter Property="Width" Value="100"/>
                    <Setter Property="Height" Value="50"/>
                <Style TargetType="Button" BasedOn="{StaticResource fe_style}" x:Name="bn_style">
                    <Setter Property="Content" Value="Hello,world"/>
            <Button Style="{StaticResource bn_style}"/>

    here is a link about "BasedOn"


    Hope this helps

    Tuesday, July 7, 2009 12:02 AM