MaterialDesignInXamlToolkit icon indicating copy to clipboard operation
MaterialDesignInXamlToolkit copied to clipboard

WindowChrome affecting drawer animations performance

Open XspeedPL opened this issue 7 years ago • 5 comments

I've noticed that drawer animations performance drops a lot when the window is maximized while using WindowChrome options with WindowStyle.None

Adding this code to any window and maximizing it should allow to reproduce the issue:

<Window
	...
	WindowStyle="None"
	WindowState="Maximized">
	<!-- Important change -->
	<WindowChrome.WindowChrome>
		<WindowChrome CaptionHeight="32"/>
	</WindowChrome.WindowChrome>
	<!-- /Important change -->
	<md:DrawerHost IsLeftDrawerOpen="{Binding IsChecked, ElementName=MenuToggle}" Margin="5">
		<md:DrawerHost.LeftDrawerContent>
			<StackPanel MinWidth="200" DockPanel.Dock="Left" WindowChrome.IsHitTestVisibleInChrome="True">
				<ToggleButton Style="{DynamicResource MaterialDesignHamburgerToggleButton}" HorizontalAlignment="Right" Margin="8 4" IsChecked="{Binding IsChecked, ElementName=MenuToggle, Mode=TwoWay}"/>
			</StackPanel>
		</md:DrawerHost.LeftDrawerContent>
		<DockPanel>
			<md:ColorZone Padding="8 4" md:ShadowAssist.ShadowDepth="Depth2" Mode="PrimaryMid" DockPanel.Dock="Top" Name="TitleBar">
				<DockPanel Height="37">
					<ToggleButton Style="{DynamicResource MaterialDesignHamburgerToggleButton}" IsChecked="False" Name="MenuToggle" DockPanel.Dock="Left" WindowChrome.IsHitTestVisibleInChrome="True"/>
				</DockPanel>
			</md:ColorZone>
			<Grid>
			</Grid>
		</DockPanel>
	</md:DrawerHost>
</Window>

XspeedPL avatar Nov 15 '18 17:11 XspeedPL

It's not only the DrawerHost, which is affected by this. I also recognized this behavior for the DialogHost. Than I also tested some simple animations without MaterialDesign and with WindowChrome. Here I didn't see any difference between WindowState.Normal and WindowState.Maximized.

So my first idea was like yours, that it has only something to do with the DialogHost or DrawerHost implementations.

Than I added ControlsEx. And now, I don't know if it's an issue, which can be solved here, or if it's a general bug in Microsofts WindowChrome implementation. Because I could get rid of the performance problem by using the ControlzEx WindowChrome Fork.

Hopefully in future, when all WPF gets OSS, the team around ControlzEx can merge their improvements to the WindowChrome back to Microsofts version.

For quick fix right now I think you can try to install ControlsEx and change your code to something like this:

<Window
   ...
   xmlns:ctrlz="urn:controlzex"
   WindowStyle="None"
   WindowState="Maximized">

   <ctrlz:WindowChrome.WindowChrome>
       <ctrlz:WindowChrome CaptionHeight="32"/>
   </ctrlz:WindowChrome.WindowChrome>
   ...
</Window>

And also ctrlz:WindowChrome.IsHitTestVisibleInChrome="True" where needed.

AlexejLiebenthal avatar Feb 08 '19 13:02 AlexejLiebenthal

Could it be that the gpu/windows thinks the entire drawer is offscreen?

jespersh avatar Feb 08 '19 15:02 jespersh

Also tried that, with a huge border, to be sure that the DrawerHost Control isn't offscreen. But still you get also bad performance. And the window will still be offscreen with the Microsoft `WindowChrome'.

AlexejLiebenthal avatar Feb 08 '19 15:02 AlexejLiebenthal

I have same problem with dialogs. I got only like 5 FPS with this config:

    <WindowChrome.WindowChrome>
        <WindowChrome
            CaptionHeight="45"
            CornerRadius="10"
            GlassFrameThickness="0,0,0,0"
            ResizeBorderThickness="4" />
    </WindowChrome.WindowChrome>

Sometimes there is no animation at all :(

M0n7y5 avatar Oct 23 '20 12:10 M0n7y5

Also ControlzEx solution no is longer working

M0n7y5 avatar Oct 23 '20 12:10 M0n7y5