0

I want to change the size of my MainWindow, and failed in using "Height", "Width", the problem as "WMC0011 Unknown member 'Height' on element 'Window'

Also, when I use member "Title", problem as "WMC0612 The XAML Binary Format (XBF) generator reported syntax error '0x09C4' : Property Not Found"

<Window
    x:Class="speech_emotion.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:speech_emotion"
    
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
    Title="speech_emotion" Height="50"
    mc:Ignorable="d">

</Window>

I want to know how to solve these two problems? How can I change the size of window? My editor is vs2019. Thanks for your help.

1 Answers1

1

You can't specify the size of the Microsoft.UI.Xaml.Window directly.

As demonstrated in the docs, you should programmatically retrieve an AppWindow from the WinUI 3 window and then resize this one using the Resize method:

// Retrieve the window handle (HWND) of the current (XAML) WinUI 3 window.
var hWnd =
    WinRT.Interop.WindowNative.GetWindowHandle(this);

// Retrieve the WindowId that corresponds to hWnd.
Microsoft.UI.WindowId windowId =
    Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWnd);

// Lastly, retrieve the AppWindow for the current (XAML) WinUI 3 window.
Microsoft.UI.Windowing.AppWindow appWindow =
    Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);

if (appWindow != null)
{
    appWindow.Resize(new Windows.Graphics.SizeInt32(appWindow.Size.Width, 50));
}

You cannot specify the size of the window directly in the XAML markup.

mm8
  • 163,881
  • 10
  • 57
  • 88