如何在WPF中将TargetType设置为此?

3

我有一个自定义的(例如称为),其中包含多个子控件。 我想创建一个,其中包含一组样式和依赖属性分配,用于设计目的(没有样式,控件看起来像一堆泥巴)。 以后我会注释这些样式。

问题在于,我不知道如何设置样式的,以指向正在开发的。

以下是示例:

<UserControl.Resources>
    <Style TargetType="this">
    </Style>
</UserControl.Resources>
1个回答

5
你可以像这样做:
<UserControl x:Class="YourProjectName.UserControl1"
             xmlns:local="clr-namespace:YourProjectName"

    <UserControl.Resources>
        <Style TargetType="{x:Type local:UserControl1}">
            <Setter Property="Background" Value="Green"></Setter>
        </Style>
    </UserControl.Resources>

</UserControl>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接