我正在尝试使此答案起作用,但是却出现了错误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>
您有两个直接子级<StackPanel.Style>
:Setter
,Margin
因为A属于Style
和Style
本身。您只能为分配一个东西<StackPanel.Style>
,而那个东西必须是一个Style
。
因此,只需将Margin
setter移动到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] 删除。
我来说两句