Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Setting property through style for base class does not update property value for derived class
1 replies. Latest Post by Mog Liang - MSFT on July 7, 2009.
(0)
shekhard...
Member
6 points
7 Posts
07-01-2009 9:47 PM |
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,
<
Mog Lian...
All-Star
15884 points
1,541 Posts
07-07-2009 12:02 AM |
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