0

我正在创建一个 WPF UserControl 并在其中定义了一个名为“Orientation”的依赖项属性。它的类型Dock允许我设置值 Top、Bottom、Left 和 Right。UserControl 在其 XAML 中还包含一个 Border 元素。根据 Orientation 属性的值,边框应出现在一侧。这是我到目前为止定义的触发器:

<Trigger Property="Orientation" Value="Bottom">
    <Setter Property="BorderThickness" Value="0,1,0,0"/>
</Trigger>
<Trigger Property="Orientation" Value="Top">
    <Setter Property="BorderThickness" Value="0,0,0,1"/>
</Trigger>
<Trigger Property="Orientation" Value="Left">
    <Setter Property="BorderThickness" Value="0,0,1,0"/>
</Trigger>
<Trigger Property="Orientation" Value="Right">
    <Setter Property="BorderThickness" Value="1,0,0,0"/>
</Trigger>

我现在尝试在 Border 样式中使用这些触发器,但它们找不到 Orientation 属性。然后我尝试在 UserControl 的样式中使用它,将 TargetName 设置为我的 Border,但 TargetName 无法设置。

正确的 XAML 代码看起来如何?

4

1 回答 1

1

在您的边框样式中使用 DataTrigger 而不是 Trigger 例如

<DataTrigger Binding="{Binding Orientation, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" Value="Bottom">
    <Setter Property="BorderThickness" Value="0,1,0,0"/>
</DataTrigger>

同样更新所有触发器

于 2013-10-09T15:09:57.547 回答