Tower
Tower

Reputation: 102785

How to target different type of controls in WPF styles?

I want to set different backgrounds for GridSplitter's who are horizontal vs vertical. This is because I have a linear gradient and I need to rotate it 90deg depending on the alignment of the grid splitter.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="{x:Type GridSplitter}">
        <Setter Property="Background" Value="Red" /> <!-- How to get this red applied to only Vertical for instance? -->
    </Style>
</ResourceDictionary>

So the question is: how do I target vertical splitters and horizontal splitters separately?

Upvotes: 1

Views: 257

Answers (2)

Tower
Tower

Reputation: 102785

Okay looks like I got it:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="{x:Type GridSplitter}">
        <Style.Triggers>
            <Trigger Property="VerticalAlignment" Value="Stretch">
                <Setter Property="Background" Value="#F7F7F7" />
            </Trigger>

            <Trigger Property="HorizontalAlignment" Value="Stretch">
                <Setter Property="Background" Value="red" />
            </Trigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>

Upvotes: 1

brunnerh
brunnerh

Reputation: 184506

Use Style.Triggers to apply setters conditionally.

Upvotes: 3

Related Questions