我正在玩弄Silverlight,并尝试设置一个样式以应用于所有TextBlock。以下是XAML:
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="10, 10, 10, 10" />
</Style>
我收到了一个错误消息:属性TargetType的值{x:Type TextBlock}无效。
我从MSDN上复制并粘贴了这段代码,所以我有点不明白为什么会出现这个错误。
编辑:
这是我现在尝试的完整代码:
<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>
以下是它的外观: