Bradley Uffner
Bradley Uffner

Reputation: 17001

WPF window flickers when resizing

I have a very simple window, defined with the following XAML (There is currently no logic in the View Model):

<Window x:Class="WpfViewer.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:local="clr-namespace:WpfViewer"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        Title="MainWindow"
        Width="525"
        Height="350"
        d:DataContext="{d:DesignInstance local:MainWindowVm}"
        mc:Ignorable="d">
    <Grid Margin="8">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" />
            <ColumnDefinition Width="8" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0"
                    Grid.Column="0"
                    Grid.ColumnSpan="3"
                    Orientation="Horizontal" Margin="0,0,0,8">
            <TextBlock Text="Object" />
            <!--  breadcrumbs  -->
        </StackPanel>
        <Border Grid.Row="1"
                Grid.Column="0"
                BorderBrush="Black"
                BorderThickness="1" />
        <GridSplitter Grid.Row="1"
                      Grid.Column="1"
                      Width="8"
                      Background="{DynamicResource {x:Static SystemColors.WindowBrush}}"
                      ResizeBehavior="PreviousAndNext" />
        <Border Grid.Row="1"
                Grid.Column="2"
                BorderBrush="Black"
                BorderThickness="1" />
    </Grid>
</Window>

As the user resizes the window, the new area of the window flickers black. enter image description here

Is there any way to prevent this flickering?


I do not beleive that this existing question is a duplicate. It involves completely custom windows, with animations.

Prevent WPF window flicker

Upvotes: 3

Views: 4128

Answers (4)

Logix
Logix

Reputation: 590

I know this is old, but as the accepted answer suggests, this is because of the debugging tools. You will notice a significant performance improvement from disabling UI Debugging Tools for XAML, provided you don't use or rely on them:

Tools > Options > Debugging > General > Enable UI Debugging Tools for XAML

and of course running the app outside of the debugger should show you the application's actual performance. Running your program using any IDE as a debugger will undoubtedly slow it down significantly, this is just a result of the way debuggers interact with your program, monitoring everything it does and listening for exceptions, etc.

Upvotes: 5

mark50
mark50

Reputation: 15

Use UWP Host it may solve your issue.

See this for sample screenshot:

Screenshot

You can remove complete titlebar from here. Give the Attribute ShowTitlebar="false" in mainwindow.

Upvotes: -2

Selastin
Selastin

Reputation: 11

I was having the same issue but I solved it by using the nuget package edge.windowchrome an upgraded version of Microsoft.Windows.Shell

It helped me to remove the flicker

Note: it will only work very well with latest version of Windows 10 (redstone)

Upvotes: 0

bl0rq
bl0rq

Reputation: 49

This is being caused by the debug-time additions to the window. Try running it without the debugger attached.

Upvotes: 3

Related Questions