Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating a sub-class library of common controls?
Message
From
06/07/2008 12:28:50
 
 
To
06/07/2008 00:49:15
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01328319
Message ID:
01329251
Views:
12
>So if you put a style in a resource without giving it a key name, it will apply to all targets on the page, right?
>
>So, how would you let it hit all targets, but then override a setting or two on just one or two targets? I would think you could use Basedon in the target, but since you didn't give the master style a key name, how would you accomplish this partial override?

Styles don't automatically cascade into other styles, so this is the pattern I worked out. Not sure if I've actually used it yet.
<!-- Base Style Definition -->
<Style x:Key="myBaseTextBlockStyle" TargetType="TextBlock">
  <Setter Property="Foreground" Value="Red"/>
</Style>

<!-- Apply Base Style to UnStyled Elements -->
<Style TargetType="TextBlock" BasedOn="{StaticResource myBaseTextBlockStyle}">
</Style>

<!-- Subclasssed Style -->
<Style  x:Key="myFancyTextBlockStyle" TargetType="TextBlock" BasedOn="{StaticResource myBaseTextBlockStyle}">
  <Setter Property="Foreground" Value="Blue"/>
</Style>
Previous
Reply
Map
View

Click here to load this message in the networking platform