我正在使用WPF Shell集成库来创建我的wpf应用程序的自定义chrome.一切都很好,但是当最大化应用程序时,屏幕外有6或7个像素.
这是我正在使用的代码:
<Style TargetType="{x:Type local:MainWindow}">
<Setter Property="shell:WindowChrome.WindowChrome">
<Setter.Value>
<shell:WindowChrome
ResizeBorderThickness="6"
CaptionHeight="10"
CornerRadius="0"
GlassFrameThickness="1"/>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MainWindow}">
<Grid>
<Border BorderThickness="1" BorderBrush="#389FD1" Background="#389FD1">
<ContentPresenter Margin="0,22,0,0" Content="{TemplateBinding Content}"/>
</Border>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" >
<TextBlock Text="{Binding NombreUsuario}" Foreground="White" Margin="5,5,20,5" Opacity=".8" />
<Button Style="{StaticResource ImageButton}" Height="20" Width="20" Margin="0" Click="WindowMinimize" shell:WindowChrome.IsHitTestVisibleInChrome="True">
<Image Height="10" Width="10" Source="/Resources/Images/minimize.png" />
</Button>
<Button Style="{StaticResource ImageButton}" Height="20" Width="20" Margin="0" Click="WindowMaximizeRestore" shell:WindowChrome.IsHitTestVisibleInChrome="True" >
<Image Height="10" Width="10" Source="/Resources/Images/maximize.png" />
</Button>
<Button Style="{StaticResource ImageButton}" Height="20" Width="20" …Run Code Online (Sandbox Code Playgroud) 我使用WindowChrome来自定义Window.当我最大化窗口时,边缘不在屏幕上.我使用以下代码来解决此问题:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="50" CornerRadius="0" GlassFrameThickness="0" NonClientFrameEdges="None" ResizeBorderThickness="5" UseAeroCaptionButtons="False" />
</WindowChrome.WindowChrome>
<Grid>
<Grid.Style>
<Style TargetType="{x:Type Grid}">
<Setter Property="Margin" Value="0" />
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=WindowState}" Value="Maximized">
<Setter Property="Margin" Value="{x:Static SystemParameters.WindowResizeBorderThickness}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<Border BorderThickness="2" BorderBrush="Blue" Background="Yellow" />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
我的问题:如何获得正确的像素数,以便边缘不在屏幕之外.
SystemParameters.WindowResizeBorderThickness包含的值不正确.
当我点击全屏按钮时,我的WPF应用程序(使用Elysium Extra)在窗口右侧有一个边距:
在右侧,您可以看到我的桌面背景.
我检查是否有保证金,但它设置为0 px所有方面.我也定了
this.MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;
this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
Run Code Online (Sandbox Code Playgroud)
App.xaml中:
<extra:ElysiumApplication x:Class="CTS.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:extra="http://schemas.extra.com/ui"
xmlns:local="clr-namespace:CTS"
Theme="Dark"
StartupUri="MainWindow.xaml" />
Run Code Online (Sandbox Code Playgroud)
MainWindow.xaml:
<extra:Window x:Class="CTS.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:extra="http://schemas.extra.com/ui"
xmlns:local="clr-namespace:CTS"
mc:Ignorable="d"
Title="..." Height="521.877" Width="1239.945" FontFamily="Open Sans" Foreground="#FF0970D1" Background="#FF22313F">
....
Run Code Online (Sandbox Code Playgroud)
编辑:我已经检查了Elysium Extra演示应用程序.它也有同样的问题,所以它似乎是由框架引起的.但是,我想继续使用它.
我怎样才能摆脱这个边际?
在WPF中,有没有办法检查触发器中窗口的"WindowState"属性?我尝试使用"0","最小化"和"WindowState.Minimized"的值.
例:
<Window.Triggers>
<Trigger Property="WindowState" Value="Minimized">
<Setter Property="ShowInTaskBar" Value="False" />
</Trigger>
</Window.Triggers>
Run Code Online (Sandbox Code Playgroud)