gpt4 book ai didi

c# - 属性 "Style"只能设置一次

转载 作者:行者123 更新时间:2023-12-04 00:24:24 27 4
gpt4 key购买 nike

我正在尝试获取this answer工作,但是我收到错误The property "Style"can only be set one.。这是为什么?

这就是我所拥有的:

<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>

最佳答案

您有 <StackPanel.Style> 的两个直系子代:一个Setter对于 Margin属于 Style 范围内,以及 Style本身。您只能将一件事情分配给 <StackPanel.Style> ,那东西必须是 Style

所以只需移动 Margin Style 内的 setter 元素:

<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>

简而言之,你的风格有点时尚失礼

关于c# - 属性 "Style"只能设置一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37279456/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com