【发布时间】:2009-03-20 18:10:51
【问题描述】:
只是稍微玩弄一下 Silverlight 并尝试设置一种样式以应用于所有 TextBlock。以下 XAML:
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="10, 10, 10, 10" />
</Style>
给我错误Invalid attribute value {x:Type TextBlock} for property TargetType.
我从 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>
它的外观如下:
【问题讨论】:
-
你想把这个样式放在哪里?在 Window.Resources 中?
-
所以您希望这种样式级联到用户控件元素中的所有文本块?
标签: .net silverlight xaml