Silverlight的:无效的属性类型的TargetType =" {X:类型的TextBlock}"类型、属性、Silverlight、TextBlock

2023-09-03 01:29:24 作者:我没有城府

只是在摆弄的Silverlight了一下,试图建立一种风格适用于所有的TextBlocks。下面的XAML:

 <风格的TargetType ={X:类型的TextBlock}>
   < setter属性=保证金VALUE =10,10,10,10/>
< /样式和GT;
 

给我的错误无效的属性值{X:类型的TextBlock}。物业的TargetType

我复制并粘贴该位从MSDN所以我有点失去了,为什么我得到这个错误。

编辑:

下面是完整的code我试图现价:

 <用户控件X:类=NIRC.Page
    的xmlns =htt​​p://schemas.microsoft.com/winfx/2006/xaml/$p$psentation
    的xmlns:X =htt​​p://schemas.microsoft.com/winfx/2006/xaml
    WIDTH =400高度=300>
    < UserControl.Resources>
        <风格的TargetType =TextBlock的>
            < setter属性=保证金VALUE =10/>
            < setter属性=前景VALUE =红/>
        < /样式和GT;
    < /UserControl.Resources>
    <的TextBlock>您好!世界< / TextBlock的>
< /用户控件>
 
revit如何修改墙体类型

下面是它的外观:

解决方案

Silverlight不支持通过通用的样式隐含的造型(即用的TargetType,但没有一个静态的资源键 - X:键=),但WPF确实

您需要明确申请使用的StaticResource引用方式对你的元素,你想用风格的每个实例类型={的StaticResource的样式名的}。

借助 Silverlight工具包有一个隐含的样式管理器(ISM),获取解决这个从包装Silverlight的标记和应用样式ResourceDictionaries通过解析内容

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:

解决方案

Silverlight does not support implicit styling via generic Styles (i.e. with a TargetType but without a static resource key - x:Key="") but WPF does.

You need to explicitly apply Styles using StaticResource references on each instance of your element that you want styled using Style="{StaticResource stylename}".

The Silverlight toolkit has an Implicit Style Manager (ISM) that gets around this by wrapping Silverlight markup and applying styles from ResourceDictionaries by parsing the content.