microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

Unable to set Window Title in XAML

Open mrlacey opened this issue 4 years ago • 28 comments
trafficstars

Describe the bug

In WinUI3preview3, unable to build a project if set the Window Title in XAML.

Steps to reproduce the bug

  1. Create a new Blank App, Packaged (WinUI in Desktop)
  2. Change the content of MainWindow.xaml to add the following on line 8
<Window
    x:Class="App68.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App68"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="my app"
    mc:Ignorable="d">
  1. Build the solution
  2. See an exception:

MainWindow.xaml(8,5): XamlCompiler error WMC0612: The XAML Binary Format (XBF) generator reported syntax error '0x09C4' : Property Not Found

  1. Remove the change in the XAML file and set the window Title in the constructor. e.g.:
    public MainWindow()
    {
        this.InitializeComponent();
        this.Title = "my app";
    }
  1. Run the app and see the title displayed correctly.

Expected behavior

It should be possible to set the Window Title in XAML.

Screenshots

Version Info

NuGet package version: Microsoft.WinUI 3.0.0-preview3.201113.0

Windows app type:

UWP Win32
Yes
Windows 10 version Saw the problem?
Insider Build (xxxxx)
May 2020 Update (19041) Yes
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Xbox
Surface Hub
IoT

Additional context

mrlacey avatar Nov 24 '20 16:11 mrlacey

@ocalvo FYI, who was it that finished up the title bar work in winui3?

StephenLPeters avatar Nov 24 '20 22:11 StephenLPeters

⚠ Still a bug in Preview 4. @StephenLPeters

riverar avatar Feb 16 '21 21:02 riverar

Still broken in WinUI 3 production, Project Reunion 0.5.7.

riverar avatar May 14 '21 20:05 riverar

Still Broken.

antoprd avatar Jun 02 '21 20:06 antoprd

still not fixed

Darkatek7 avatar Jun 30 '21 12:06 Darkatek7

Still not fix in Reunion 0.8

klauszou avatar Jul 05 '21 09:07 klauszou

Still broken in 1.0-experimental1. @marb2000 We're not going to ship 1.0 with the inability to set the window title right? RIGHT? 😂

riverar avatar Aug 15 '21 21:08 riverar

There is an (ugly) workaround though. In your Window sub class add this:

        /// <summary>
        /// Gets or sets the window title.
        /// </summary>
        public new string Title
        {
            get => base.Title;
            set => base.Title = value;
        }

I had to apply that workaround to WinUIEx well: https://github.com/dotMorten/WinUIEx/blob/86c86233512565873ffc413342dd88ed04dbca14/src/WinUIEx/WindowEx.cs#L81-L88

However I'm worried that the lack of window management APIs and Title can't even be set from XAML as we're used to is going to be extremely off-putting to users. Is the amount of code you need to write acceptable, just to do basic management of your window, in a v1.0 release? (hint: I don't think the answer isn't yes).

I'm worried people will take one look at WinUI and see that basic window management APIs are more or less non-existent (or as shown above overly complicated to use), and write off WinUI before it even had a chance.

dotMorten avatar Aug 15 '21 22:08 dotMorten

@dotMorten 🤠 It's pretty ridiculous that this still blows up XAML with an obscure error. But agreed. 👍

riverar avatar Aug 15 '21 22:08 riverar

I had started writing WinUIEx as a temporary stop-gap to the lack of Windowing APIs, but hadn't bothered completely finishing it up or publishing a nuget, because I naturally assumed basic Windowing APIs would be in 1.0, and I was also reluctant because the entire implementation just feels like one giant band-aid. It seems like I need to do bring this all the way to at least close some of these obvious gaps for 1.0.

dotMorten avatar Aug 15 '21 22:08 dotMorten

Still... present in Preview 1. They got less than two months to fix this.

fourdragons avatar Sep 20 '21 00:09 fourdragons

Don't think this is getting fixed any time soon, now that there's a workaround. 😞

riverar avatar Sep 20 '21 00:09 riverar

It's still broken. I'm currently using the constructor method for temporary fix. this.Title = "App Title";

jorcus avatar Oct 10 '21 06:10 jorcus

Unfortunately, per the latest engineering plan, the bug fix won't make the v1.0 Stable release (GA) and was moved to v1.1

marb2000 avatar Oct 11 '21 17:10 marb2000

This is ridiculous as a so basic function doesn't work on the official version 1.0.

younky-yang avatar Nov 18 '21 13:11 younky-yang

Yep, just decided to try UWP and WinUI but this thing is just horrible to work with. Back to good ole win32 it is

alexugthub avatar Nov 28 '21 00:11 alexugthub

Not sure if directly related but when using MAUI blazor app template targeting Windows, title doesnt seem to work either from setting in xaml or ctor of mainpage.

olabacker avatar Dec 07 '21 12:12 olabacker

Similar to what olabacker found, when using a .NET MAUI App template targeted on Windows the title won't appear when defined either in MainPage.xaml or in MainPage.xaml.cs. I tried adding dotMorten's snippet to MainPage.xaml.cs and setting the property in the constructor, but still no title appeared. As this template produces a WinUI app, presumably it's the same problem.
Apps for scientific data processing can use upwards of 50 forms and dialogs in old Windows Forms app speak, having a form or window title is essential otherwise the user won't know where they are or how what they are seeing relates to documentation..

esaMark avatar Dec 19 '21 17:12 esaMark

The bug which could not die. Maybe in 1.1?

mstasak avatar Mar 08 '22 18:03 mstasak

Are you serious? You can't even set title in WinUI3 app?

EDIT:

I have set it programatically in App.xaml.cpp and it worked. Seems like an XAML only issue.

window = make<MainWindow>();
window.Title(L"My title");
window.Activate();

bugproof avatar Mar 28 '22 10:03 bugproof

I have set it programatically in App.xaml.cpp and it worked. Seems like a XAML only issue.

Which is exactly what the first post says. But yeah, that's just one of the wonderful experience developers get when they try out WinUI.

Symbai avatar Mar 28 '22 11:03 Symbai

Just tried with the latest v1.1.0-preview1 and still doesn't work. And to make matters worse, the error message is extremely unhelpful with no indication about what property or where:

1>MainWindow.xaml(8,22): XamlCompiler error WMC0612: The XAML Binary Format (XBF) generator reported syntax error '0x09C4' : Property Not Found

If you can't fix it, at least fix the error message.

dotMorten avatar Mar 30 '22 23:03 dotMorten

Perhaps MainWindow Title was purposefully left out for a while so engineers would have practice implementing WinUI3 properties. Is it a coincidence that the main C++ bind example is a Title property? :-) https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/binding-property

I use C++ coming from C# XAML, so I'm finding this to be a great exercise. :-)

CodePagesNet avatar Apr 27 '22 18:04 CodePagesNet

Still broken a year and a half later...

younesaassila avatar May 16 '22 12:05 younesaassila

Welp still not fixed. I think we'll have to wait about at least 5 more years for this issue to be fixed cause apparently there are other 2.7k current open issues.

kaismic avatar Jun 18 '22 10:06 kaismic

@soobakjonmat I agree this is annoying. But it is by no means a showstopper like many other issues. You can still set it in code behind or use something like WinUIEx’s WindowEx to do it.

dotMorten avatar Jun 18 '22 16:06 dotMorten

@soobakjonmat I agree this is annoying. But it is by no means a showstopper like many other issues. You can still set it in code behind or use something like WinUIEx’s WindowEx to do it.

Yeah I'm just saying that it's probably gonna take a while to get it fixed. I'm using this.Title = so no problem there. And while reading my own comment again, it does sound sarcastic and apologies for that. I guess I was a bit grumpy while I was writing that comment cause I haven't slept all night on that day.

kaismic avatar Jun 19 '22 00:06 kaismic

Maybe it's worth mentioning that the workaround for C++ looks like this:

MainWindow::MainWindow()
{
    InitializeComponent();
    this->Title(L"Your Window Title");
}

oold avatar Sep 01 '22 14:09 oold

Still not working without workaround...

breenbob avatar Nov 17 '22 16:11 breenbob

I think we have been making a XAML Title assumption for WinUI based on WPF experience. Code samples here imply that Title in XAML is not intended, and by leaving it out of XAML, we are led to discover the Title Bar capabilities: https://learn.microsoft.com/en-us/windows/apps/develop/title-bar?tabs=wasdk

I.e.: I think that we have a "Works as intended" status here.

CodePagesNet avatar Dec 24 '22 03:12 CodePagesNet

I think it’s a reasonable assumption. What I think went wrong here is the window is a non-WinUI window without the WinUI stuff in it (like inheriting from Dependency Object, understand styling etc). WinUI should make its own Window type that wraps the underlying Windows App SDK window and provide a proper developer experience that’s expected in 2022. I don’t buy the argument that it is as designed and existing expectations aren’t valid - if you want people to move over you need to provide an experience at least on par. The entire Window class is a mess to work with and needs something designed properly for the xaml developer.

dotMorten avatar Dec 24 '22 03:12 dotMorten