Just playing around with Silverlight a bit and trying to set a style to apply to all TextBlocks. The following XAML:
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="10, 10, 10, 10" />
</Style>
Gives me the error Invalid attribute value {x:Type TextBlock} for property TargetType.
I copied and pasted this bit from the MSDN so I'm a little lost as to why I'm getting this error.
EDIT:
Here's the full code I'm attempting now:
<UserControl x:Class="NIRC.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<UserControl.Resources>
<Style TargetType="TextBlock">
<Setter Property="Margin" Value="10" />
<Setter Property="Foreground" Value="Red" />
</Style>
</UserControl.Resources>
<TextBlock>Hello World!</TextBlock>
</UserControl>
Here's how it looks:
alt text http://www.netortech.com/Content/slhw.jpg
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…