V
V
Vitaly2018-07-09 11:23:36
WPF
Vitaly, 2018-07-09 11:23:36

WPF How to get rid of window flicker?

Hello, please help me figure it out :)
Done: changed the style of the window.
Got it: When resizing, the window starts flickering. It flickers on Win 7. I did not notice this in Win 10.
If you set the AllowsTransparency="True" property, the flickering disappears, but this property does not suit you (CPU consumption increases significantly), it must be FALSE.
I see two options

  1. Understand why with AllowsTransparency="True" the animation loses FPS a lot, jerks are visible, and without animation, CPU consumption increases significantly
  2. Remove flicker when AllowsTransparency="False"

An example of a flickering window on github: https://github.com/KovtunV/WindowFlickers

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cyber_roach, 2019-02-20
@cyber_roach

There are a few bugs in the style code
1) don't use extra borders creating unnecessary tree branches

<!--Back border-->
                            <Border x:Name="BackBorder"
                                    Background="LightGray">
                            </Border>

you already had a border above to make both a frame and a background, why are there extra ones?
2) You forgot the most important window style element, the AdornerDecorator.
It seems that it does not affect anything, but in fact it is because of it that all the glitches occur, you need to wrap the ContentPresenter (or rather, all user content) in
it
, I always advise you to refer to the documentation on standard styles, most likely you forgot some important part of the code (most often some "PART_")
https://docs.microsoft.com/ru-ru/dotnet/framework/.. 3 )
use bindings to window properties (beground, border, border thickness) inside the template
4) well, you have a strange style applied x:Type local:MainWindow instead of x:Type Window
Here is an example of a style template:
<Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Window}">
                    <Border x:Name="RootContainer" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                        <AdornerDecorator>
                            <DockPanel>
                                <Border DockPanel.Dock="Top" Background="{StaticResource WindowHeaderBackgroundBrush}">
                                      <!--тут ваши стили заголовка и его элементов-->
                                </Border>
                                <ContentPresenter/>
                            </DockPanel>
                        </AdornerDecorator>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="WindowState" Value="Maximized">
                            <Setter TargetName="RootContainer" Property="Padding" Value="7"/>
                        </Trigger>
                        <Trigger Property="IsActive" Value="False">
                            <Setter TargetName="RootContainer" Property="BorderBrush" Value="#FF333333"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

If flickering after editing does not disappear on 7ke, then you still need to add a WindowChrome frame (standard window shadow and basic border) for this OS,
at least like this GlassFrameThickness="0,1,0,0"
Or abandon WindowChrome completely (but then you need some kind of custom window control that supports all the Aero features (for example, drag for the title bar and tapping on the edge of the screen), I used to use this before, but with the advent of WindowChrome properties, it became unnecessary
. recommended, the windows look too much better with it, and any custom solution will lose the standard Aero shadow in performance and non-buggy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question