使用 WPF shell 集成库最大化时窗口超出屏幕

编程入门 行业动态 更新时间:2024-10-23 04:47:22
本文介绍了使用 WPF shell 集成库最大化时窗口超出屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 WPF Shell 集成库来创建我的 wpf 应用程序的自定义镶边.一切都很好,但在最大化应用程序时,屏幕外有 6 或 7 个像素.

I'm using the WPF Shell Integration Library to create a custom chrome of my wpf app. All is good, but when maximizing the app, 6 or 7 pixels are out of the screen.

这是我正在使用的代码:

This is the code I'm using:

<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" Margin="0" Click="WindowClose" shell:WindowChrome.IsHitTestVisibleInChrome="True"> <Image Height="10" Width="10" Source="/Resources/Images/close.png" /> </Button> </StackPanel> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>

推荐答案

当窗口最大化时,Windows 会裁剪窗口的边缘以掩盖通常是调整大小的边缘.您可以通过在窗口和内容之间放置一个代理边框来解决这个问题,然后在最大化时增加厚度.

Windows crops the edges of the window when it's maximized to obscure what would normally be the resize edges. You can get around this by putting a proxy border between the window and your content and then inflate the thickness when it's maximized.

我修改了 lib 附带的示例来执行此操作,可以对您的示例进行相同的基本更改:

I modified the example that came with the lib to do this, the same basic change could be made to your sample:

<ControlTemplate TargetType="{x:Type local:SelectableChromeWindow}"> <Border BorderBrush="Green"> <Border.Style> <Style TargetType="{x:Type Border}"> <Setter Property="BorderThickness" Value="0"/> <Style.Triggers> <DataTrigger Binding="{Binding ElementName=ThisWindow, Path=WindowState}" Value="Maximized"> <Setter Property="BorderThickness" Value="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowResizeBorderThickness}"/> </DataTrigger> </Style.Triggers> </Style> </Border.Style> <Grid [...]/> </Border> </ControlTemplate>

希望能帮到你.

对于 4.5 及更高版本,系统参数略有不同,例如:

For 4.5 and above, the SystemParameters are a little different, e.g.:

<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:MainWindow}}, Path=WindowState}" Value="Maximized"> <Setter Property="BorderThickness" Value="{Binding Source={x:Static SystemParameters.WindowResizeBorderThickness}}"/> </DataTrigger>

更多推荐

使用 WPF shell 集成库最大化时窗口超出屏幕

本文发布于:2023-11-12 20:31:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582464.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:屏幕   窗口   WPF   shell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!