Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set Window Title in XAML #3689

Closed
mrlacey opened this issue Nov 24, 2020 · 47 comments
Closed

Unable to set Window Title in XAML #3689

mrlacey opened this issue Nov 24, 2020 · 47 comments
Labels
area-TitleBar Issues related to custom window title bars. needs-triage Issue needs to be triaged by the area owners product-winui3 WinUI 3 issues team-Reach Issue for the Reach team
Milestone

Comments

@mrlacey
Copy link
Contributor

mrlacey commented Nov 24, 2020

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

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Nov 24, 2020
@StephenLPeters StephenLPeters added product-winui3 WinUI 3 issues and removed needs-triage Issue needs to be triaged by the area owners labels Nov 24, 2020
@StephenLPeters
Copy link
Contributor

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

@riverar
Copy link
Contributor

riverar commented Feb 16, 2021

⚠ Still a bug in Preview 4. @StephenLPeters

@riverar
Copy link
Contributor

riverar commented May 14, 2021

Still broken in WinUI 3 production, Project Reunion 0.5.7.

@antoprd
Copy link

antoprd commented Jun 2, 2021

Still Broken.

@Darkatek7
Copy link

still not fixed

@klauszou
Copy link

klauszou commented Jul 5, 2021

Still not fix in Reunion 0.8

@riverar
Copy link
Contributor

riverar commented Aug 15, 2021

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? 😂

@dotMorten
Copy link
Contributor

dotMorten commented Aug 15, 2021

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.

@riverar
Copy link
Contributor

riverar commented Aug 15, 2021

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

@dotMorten
Copy link
Contributor

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.

@fourdragons
Copy link

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

@riverar
Copy link
Contributor

riverar commented Sep 20, 2021

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

@bpulliam bpulliam added the area-TitleBar Issues related to custom window title bars. label Oct 8, 2021
@jorcus
Copy link

jorcus commented Oct 10, 2021

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

@marb2000
Copy link
Contributor

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

@younky-yang
Copy link

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

@alexmro
Copy link

alexmro commented Nov 28, 2021

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

@olabacker
Copy link

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.

@esaMark
Copy link

esaMark commented Dec 19, 2021

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..

@mstasak
Copy link

mstasak commented Mar 8, 2022

The bug which could not die. Maybe in 1.1?

@bugproof
Copy link

bugproof commented Mar 28, 2022

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();

@dotMorten
Copy link
Contributor

@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.

@kaismic
Copy link

kaismic commented Jun 19, 2022

@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.

@oold
Copy link

oold commented Sep 1, 2022

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

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

@breenbob
Copy link

Still not working without workaround...

@CodePagesNet
Copy link

CodePagesNet commented Dec 24, 2022

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.

@dotMorten
Copy link
Contributor

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.

@CodePagesNet
Copy link

CodePagesNet commented Dec 24, 2022

You may be right. I think the TitleBar capabilities may only apply to Windows 11. I'm working with WinUI 3 now, so if I gain any further useful insight, I'll try to keep in mind to share it here.

@MarkBrainfire
Copy link

WinUI is the future of Windows desktop development. And this is STILL broken.
Microsoft needs to double the size of its WinUI development team.
WinUI desktop applications are the future of software development as I point out in my website:

https://WinUI3.org

@codendone codendone added the fixed-internally This bug has been fixed, and the fix will be shipped in the next version of WinUI 3. label Feb 14, 2023
@AMArostegui
Copy link

Agreed, this is only a small annoyance, but such a simple feature to be reported and still broken after almost two years is scary.

Makes one think about Microsoft commitment to WinUI3.

So far I haven't hit a roadblock. Yes many minor bugs, a workaround here and there, but nothing remarkable. But it looms large the possibility of finding a major bug in the future that Microsoft won't address.

@bpulliam bpulliam added fixed-in-WinAppSDK1.3 and removed fixed-internally This bug has been fixed, and the fix will be shipped in the next version of WinUI 3. labels May 9, 2023
@bpulliam
Copy link
Contributor

bpulliam commented May 9, 2023

The ability to set the Title was added in WinAppSDK 1.3, but there was an issue with it. That issue has been fixed in 1.3.1 that is now available.

@dotMorten
Copy link
Contributor

@bpulliam Don't you mean v1.3.230502000 ? Congrats on 171000 builds in a month :-D

@bpulliam
Copy link
Contributor

bpulliam commented May 9, 2023

Well played :)

@riverar
Copy link
Contributor

riverar commented May 10, 2023

For those reading this and are confused like I was, Windows App SDK 1.3 Preview 1 (referred here as 1.3.1) shows up on NuGet as 1.3.230228005-preview1 for whatever silly reason. You'll want to add that to your project to pick up this change.

@riverar
Copy link
Contributor

riverar commented May 10, 2023

So, I tried this and it doesn't seem to work. Did either of you try it?

image

<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230228005-preview1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25357-preview" />

@bpulliam
Copy link
Contributor

@riverar 1.3.1 = 1.3.230502000 (built May 2, 2023), not preview1 (1.3.230228005-preview1 built Feb 28, 2023). Its about 2 months newer :).

@riverar
Copy link
Contributor

riverar commented May 10, 2023

Ah, was going off the documentation which has no mention of 1.3.1, sigh. image

@riverar
Copy link
Contributor

riverar commented May 10, 2023

Wow it works. The end of an era!

image

@bpulliam
Copy link
Contributor

Ah, was going off the documentation which has no mention of 1.3.1, sigh. image

The docs have been updated (https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/stable-channel#version-131-13230502000). Thanks for the heads-up

@bpulliam bpulliam added this to the WinUI 3 in WinAppSDK 1.3 milestone May 10, 2023
@jozefizso
Copy link

How is one supposed to teach developers to use WinUI 3 when the first steps with application requires searching for weird C++ code hacks?

Window sizes were solved in .NET Framework 1.0

@MartinFraAtGitHub
Copy link

Ah, was going off the documentation which has no mention of 1.3.1, sigh. image

The docs have been updated (https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/stable-channel#version-131-13230502000). Thanks for the heads-up

They say there: "Fixed issue causing apps to crash when setting the Window Title in XAML, a new capability added in 1.3.0. For more information, see GitHub issue #3689."

kaismic added a commit to kaismic/Hitomi-Scroll-Viewer that referenced this issue Jul 4, 2023
@Qiu233
Copy link

Qiu233 commented Oct 1, 2023

But setting ExtendsContentIntoTitleBar still gives the same error.

@ynkdir
Copy link

ynkdir commented Jun 5, 2024

WindowsAppSDK 1.5.3, unpackaged c#/c++

This doesn't work when setting DisableXbfGeneration=true or using XamlReader::Load().

MainWindow.xaml

<?xml version="1.0" encoding="utf-8"?>
<Window
    x:Class="App1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Title="hello">

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
        <Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
    </StackPanel>
</Window>

error

Failed to assign to property 'Microsoft.UI.Xaml.Window.Title'. [Line: 10 Position: 5]

Program fails at

IFC_RETURN(strValue.Promote(&strValueRuntimeStr));

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Jun 5, 2024
@ynkdir
Copy link

ynkdir commented Jun 7, 2024

At this line

IFC_RETURN(args.m_value.GetString(strValue));

When DisableXbfGeneration=false, type of args.m_value is valueString.
When DisableXbfGeneration=true, type of args.m_value is valueObject.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-TitleBar Issues related to custom window title bars. needs-triage Issue needs to be triaged by the area owners product-winui3 WinUI 3 issues team-Reach Issue for the Reach team
Projects
None yet
Development

No branches or pull requests