Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking the value of the window's "WindowState" in a Trigger

In WPF, is there a way to check the window's "WindowState" property in a Trigger? I've tried using the value of "0", "Minimized" and "WindowState.Minimized."

EXAMPLE:

<Window.Triggers>
    <Trigger Property="WindowState" Value="Minimized">
        <Setter Property="ShowInTaskBar" Value="False" />
    </Trigger>
</Window.Triggers>
like image 551
norlando Avatar asked Jan 12 '11 16:01

norlando


2 Answers

Or if you want a control other than the window to respond to the WindowState property you can use a DataTrigger instead:

<DataTrigger Binding="{Binding WindowState, RelativeSource={RelativeSource AncestorType=Window}}" 
             Value="Normal">
   <Setter Property="Fill" Value="Green"/>
</DataTrigger>
like image 96
Simon Stanford Avatar answered Oct 16 '22 16:10

Simon Stanford


Works like this:

<Window.Style>
    <Style TargetType="Window">
        <Style.Triggers>
            <Trigger Property="WindowState" Value="Minimized">
                <Setter Property="ShowInTaskbar" Value="False" />
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Style>

Edit: You need to place your trigger in the Window.Style.

like image 39
H.B. Avatar answered Oct 16 '22 16:10

H.B.