TransWikia.com

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.WindowChrome>
        <WindowChrome CaptionHeight="{x:Static SystemParameters.CaptionHeight}" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
</WindowChrome.WindowChrome>
    
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <TextBlock
        Grid.Row="0"
        Grid.Column="0"
        FontSize="32"
        Text="SOME UPPER CASE TEXT THAT WILL NEVER BE DISPLAYED" />
</Grid>

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.WindowChrome>
    <WindowChrome CaptionHeight="{x:Static SystemParameters.CaptionHeight}" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
</WindowChrome.WindowChrome>

Inside the view displayed by that window:

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

Correct answer by ge.go on December 3, 2020

Add your own answers!

Ask a Question

Get help from others!

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