Custom WindowChrome [ Wpf Core 3.1; MvvmCross 7.0.0 ]

Stack Overflow Asked by ge.go on December 3, 2020

How to customize the WindowChrome class while using MvvmCross?

I’ve got this:

        <WindowChrome CaptionHeight="{x:Static SystemParameters.CaptionHeight}" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />

inside my MvxWindow and the WindowStyle is set to none.
The problem is that MvxWindow doesn’t seem to display anything. That means I can’t create the buttons I need either. I don’t know if MvvmCross expects every UI element to be part of a View or what else is going on. Resizing and even right-clicking the invisible border works just fine. Is there any way to do this without having to rebuild the entire WindowChrome functionality inside a View?

One Answer

I will answer this myself;
while there is little difference in creating a custom WindowChrome with MvvmCross, I'll keep this question up in the hope that it could help someone else.

Not being able to display UI elements in MvxWindow is actually no problem at all. Just create the UI in your View and set the WindowChrome.IsHitTestVisibleInChrome property to true for each element you need.
There is basically no difference between doing this within a Window or a View. You just have to keep an eye on your CaptionHeight as your WindowChrome and your UI are now in two different scripts.
It could look like this:
Inside your MvxWindow:

    <WindowChrome CaptionHeight="{x:Static SystemParameters.CaptionHeight}" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />

Inside the view displayed by that window:

<Menu Height="{x:Static SystemParameters.WindowCaptionHeight}">
    <MenuItem Header="_Exit" WindowChrome.IsHitTestVisibleInChrome="True" />

Correct answer by ge.go on December 3, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP