6

在 WPF 中,有没有办法在触发器中检查窗口的“WindowState”属性?我尝试过使用“0”、“Minimized”和“WindowState.Minimized”的值。

例子:

<Window.Triggers>
    <Trigger Property="WindowState" Value="Minimized">
        <Setter Property="ShowInTaskBar" Value="False" />
    </Trigger>
</Window.Triggers>
4

3 回答 3

9

或者,如果您希望窗口以外的控件响应 WindowState 属性,则可以改用 DataTrigger:

<DataTrigger Binding="{Binding WindowState, RelativeSource={RelativeSource AncestorType=Window}}" 
             Value="Normal">
   <Setter Property="Fill" Value="Green"/>
</DataTrigger>
于 2017-07-06T10:12:11.457 回答
7

像这样工作:

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

编辑:您需要将触发器放在Window.Style.

于 2011-01-12T16:29:58.810 回答
0

最大化窗口时如何增加边框厚度的示例。否则,由于 WindowChrome 的怪异,边框会消失。

这个例子还去掉了标准的窗口标题,所以你必须添加你自己的最小化/最大化/关闭按钮。

<Window ResizeMode="CanResizeWithGrip"
        WindowStyle="SingleBorderWindow">
    <!-- Remove window header and border. Use with ResizeMode="CanResizeWithGrip" and WindowStyle="SingleBorderWindow". -->
    <WindowChrome.WindowChrome>
        <WindowChrome     
            CaptionHeight="1"  
            CornerRadius ="0"
            ResizeBorderThickness="4"         
            GlassFrameThickness="0">
        </WindowChrome>
    </WindowChrome.WindowChrome>            
    <Border BorderThickness="1">     
        <Border.Style>
            <Style TargetType="{x:Type Border}">
                <Style.Triggers>
                    <!-- Add to avoid border disappearing when window is maximised -->
                    <DataTrigger Binding="{Binding WindowState, RelativeSource={RelativeSource AncestorType=Window}}" 
                                 Value="Maximized">
                        <Setter Property="Margin" Value="10"/>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding WindowState, RelativeSource={RelativeSource AncestorType=Window}}" 
                                 Value="Normal">
                        <Setter Property="Margin" Value="0"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Border.Style>
        <Grid>
           <!-- Window XAML here. -->
        <Grid>
     </Border>
 </Window>
于 2019-02-19T09:58:48.810 回答