属性“样式”只能设置一次

花园巨人

我正在尝试使此答案起作用,但是却出现了错误The property "Style" can only be set once.这是为什么?

这就是我所拥有的:

<UserControl x:Class="SFVControls.Controls.Basic.BooleanRectangleView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d" 
             d:DesignHeight="20" d:DesignWidth="40">

    <StackPanel Name="stackTextPanel" Orientation="Horizontal">
        <StackPanel.Style>
            <Setter Property="Margin" Value="0,8,0,0" />
            <Style TargetType="{x:Type StackPanel}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding QuickDrawBarPinned}" Value="False">
                        <Setter Property="Margin" Value="0,8,0,0" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding QuickDrawBarPinned}" Value="True">
                        <Setter Property="Margin" Value="0,48,0,0" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </StackPanel.Style>
    </StackPanel>
</UserControl>
15ee8f99-57ff-4f92-890c-b56153

您有两个直接子级<StackPanel.Style>SetterMargin因为A属于StyleStyle本身。您只能为分配一个东西<StackPanel.Style>,而那个东西必须是一个Style

因此,只需将Marginsetter移动Style元素内:

<StackPanel Name="stackTextPanel" Orientation="Horizontal">
    <StackPanel.Style>
        <Style TargetType="{x:Type StackPanel}">


            <!-- Gotta be inside the Style, not outside. -->
            <Setter Property="Margin" Value="0,8,0,0" />


            <Style.Triggers>
                <DataTrigger Binding="{Binding QuickDrawBarPinned}" Value="False">
                    <Setter Property="Margin" Value="0,8,0,0" />
                </DataTrigger>
                <DataTrigger Binding="{Binding QuickDrawBarPinned}" Value="True">
                    <Setter Property="Margin" Value="0,48,0,0" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </StackPanel.Style>
</StackPanel>

总之,你的风格有时尚失礼

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么此XAML失败并显示“属性“内容”只能设置一次”。

来自分类Dev

为什么此XAML失败并显示“属性“内容”只能设置一次”。

来自分类Dev

是否可以定义只能设置一次的变量?

来自分类Dev

在useState中设置的React只能运行一次

来自分类Dev

属性只能在嵌套的for循环中更新一次

来自分类Dev

一次只能运行一次该功能

来自分类Dev

XSD指定一个只能在XML中使用一次的属性

来自分类Dev

木偶只能创建一次virtualenv

来自分类Dev

动画只能播放一次

来自分类Dev

onClick按钮只能工作一次

来自分类Dev

脚本只能运行一次

来自分类Dev

Android onClickListener只能运行一次

来自分类Dev

强制变量只能分配一次

来自分类Dev

Javascript onclick只能运行一次

来自分类Dev

Javascript库只能运行一次

来自分类Dev

Python:线程只能启动一次

来自分类Dev

是否只能执行一次功能?

来自分类Dev

Android onClickListener只能运行一次

来自分类Dev

该功能只能运行一次

来自分类Dev

Python:线程只能启动一次

来自分类Dev

动画只能播放一次

来自分类Dev

资源只能使用一次?

来自分类Dev

使产品只能购买一次

来自分类Dev

在Matlab中一次设置不同图的属性

来自分类Dev

如何设置一次属性并且不能更改?

来自分类Dev

在C#中一次设置多重属性

来自分类Dev

如何使用内部查询一次设置多个属性

来自分类Dev

一次随机设置`background-color`属性

来自分类Dev

属性内容设置了一次以上。WPF