Skip to main content

Microsoft Silverlight

Answered Question Setting property through style for base class does not update property value for derived classRSS Feed

(0)

shekhardivekar
shekhard...

Member

Member

6 points

7 Posts

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

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}"/>

</Style>

 

Mog Liang - MSFT
Mog Lian...

All-Star

All-Star

15884 points

1,541 Posts

Answered Question

Re: Setting property through style for base class does not update property value for derived class

Hi,

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

sample xaml 

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

here is a link about "BasedOn"

http://blogs.microsoft.co.il/blogs/alex_golesh/archive/2009/06/22/silverlight-3-quick-tip-10-styling-improvements.aspx

Hope this helps

Mog Liang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities