Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF WindowChrome causing flickering on resize

I'm using WindowChrome to restyle my window in an easy fast way but the problem is there is flickering when resizing the window, especially when resizing from left to right.

<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>

When this part WindowChrome is removed everything goes back to normal.

like image 941
HmH Avatar asked Aug 03 '18 09:08

HmH


1 Answers

Your Problem is caused by the property NonClientFrameEdges which is set to NONE. This property Gets or sets a value that indicates which edges of the window frame are not owned by the client and At least one edge must belong to the client.

So change your code to:

NonClientFrameEdges="Right"

This will solve your problem.

like image 170
Pouria Ansari Avatar answered Nov 01 '22 03:11

Pouria Ansari