Reputation: 20364
I'm creating a WPF UserControl and have defined a dependency property named "Orientation" in it. It's of the type Dock
that allows me to set the values Top, Bottom, Left and Right. The UserControl also contains a Border element in its XAML. Depending on the value of the Orientation property, the border shall appear on one side. Here's my triggers I have defined so far:
<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>
I've now tried to use these triggers in the Border's style, but they can't find the Orientation property. I've then tried to use it in the UserControl's style, with the TargetName set to my Border, but TargetName cannot be set.
How does the correct XAML code for this look like?
Upvotes: 0
Views: 103
Reputation: 18580
In your Border Style use DataTrigger instead of Trigger e.g
<DataTrigger Binding="{Binding Orientation, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" Value="Bottom">
<Setter Property="BorderThickness" Value="0,1,0,0"/>
</DataTrigger>
similarly update all the triggers
Upvotes: 1