WPF WindowChrome在调整大小时导致闪烁问题

13

我正在使用WindowChrome来以一种简单快速的方式重新设计我的窗口,但问题是当调整窗口大小时会出现闪烁,特别是从左到右调整大小时。

<Window x:Class="View.Settings"
    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"
    mc:Ignorable="d"
    Height="570" Width="800" WindowStartupLocation="CenterOwner"
    Background="{StaticResource DarkGrayBackground}" ResizeMode="CanResize" 
    WindowStyle="SingleBorderWindow"
    Title="Settings"
    WindowState="Normal">
<WindowChrome.WindowChrome>
    <WindowChrome 
        CaptionHeight="0"
        CornerRadius="0"
        GlassFrameThickness="1"
        UseAeroCaptionButtons="False"
        ResizeBorderThickness="5"
        NonClientFrameEdges="None"/>
</WindowChrome.WindowChrome>

<Border BorderBrush="Black" BorderThickness="1">
    <DockPanel HorizontalAlignment="Stretch" LastChildFill="True" Margin="0,0,0,0" VerticalAlignment="Stretch">
        <!--TitleBar-->
        <Border DockPanel.Dock="Top" BorderBrush="{StaticResource GrayBorder}" BorderThickness="0,0,0,1">
            <Grid Height="40" Background="{StaticResource WhiteBackground}">
                <DockPanel LastChildFill="False">
                    <Image DockPanel.Dock="Left" Margin="0,0,5,0" ></Image>
                    <Label DockPanel.Dock="Left" Content="{DynamicResource settings}" Margin="0,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center"></Label>
                    <Button DockPanel.Dock="Right" Style="{StaticResource CloseButton}" x:Name="CloseBtn"/>
                </DockPanel>
            </Grid>
        </Border>
        <!--Left Menu-->
        <Border DockPanel.Dock="Left" Width="180" Background="{StaticResource GrayBackground}" BorderBrush="{StaticResource GrayBorder}" BorderThickness="0,0,1,0">
            <DockPanel Margin="0,40,0,0"  Width="180" LastChildFill="False">
                <Button DockPanel.Dock="Top" Style="{StaticResource BigGrayButton}" 
                            Content="{DynamicResource general}"/>
            </DockPanel>
        </Border>
        <!--Bottom bar-->
        <Border DockPanel.Dock="Bottom" BorderBrush="{StaticResource GrayBorder}" BorderThickness="0,1,0,0" Height="40" Background="{StaticResource WhiteBackground}">
            <DockPanel LastChildFill="False">

            </DockPanel>
        </Border>
        <!--Main Page-->
        <ScrollViewer Background="{StaticResource DarkGrayBackground}" IsTabStop="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" DockPanel.Dock="Top">
            <DockPanel LastChildFill="False" Margin="10,0,10,10">
                <Label DockPanel.Dock="Top" Height="40" FontSize="16" FontWeight="SemiBold" VerticalContentAlignment="Center" Content="{DynamicResource general}"/>
                <Frame DockPanel.Dock="top" x:Name="MainFrame"></Frame>
            </DockPanel>
        </ScrollViewer>
    </DockPanel>
</Border>

当移除 WindowChrome 这一部分时,一切都恢复正常。


1
我注意到今天在一个应用程序中出现了同样的问题,该应用程序应用了类似的样式。很想看看可能的解决方案是什么。 - Rob Goodwin
如果禁用了Aero按钮,为什么这里会有“GlassFrameThickness =” 1“?另外,“ResizeBorderThickness =” 5“可能会导致调整大小的问题。 - Pavel Anikhouski
同样的问题在这里。看到解决方案会很有趣! - l33t
@dymanoid,所提供的XAML确实说明了问题。运行它,观察最右边的边框,然后从左到右调整大小(出现一些闪烁),再从右到左调整大小(更多闪烁)。 - l33t
1
@l33t,如果你所说的“闪烁”是指WPF的默认DWM行为,那么在SO上有一个很好的阅读材料 - 没有办法解决它。在我的系统上,除此之外我没有其他问题。 - dymanoid
显示剩余3条评论
1个回答

5

你的问题是由属性NonClientFrameEdges引起的,该属性设置为NONE。该属性获取或设置一个值,指示窗口框架的哪些边缘不属于客户端,而至少有一条边缘必须属于客户端。

因此,请将您的代码更改为:

NonClientFrameEdges="Right"

这将解决你的问题。


干得好!我把它改成了“底部”,在我的应用程序中看起来更好一些。 - Jason Stevenson
1
当它被设置为None以外的其他值时,会添加奇怪的空格。 - Konrad
1
我不认为这是一个真正的解决方案。 - Konrad
3
正如@Konrad所提到的,这将在指定为NonClientFrameEdges的窗口侧面添加白色边框。所以如果您的窗口边框已经是白色的,则该解决方案适用于您(因为您不会注意到这个小问题)。遗憾的是,我的窗口边框是黑色的,所以对我来说没有什么用。 - larsbw
如果您仍在寻找解决方案,我记得 ControlzEx 可以通过一些技巧解决所有这些问题:https://github.com/ControlzEx/ControlzEx#windowchromebehavior - Konrad

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接