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

Update .NET MAUI template to provide a window with a default title set #12646

Closed
vsfeedback opened this issue Jan 13, 2023 · 17 comments
Closed
Labels
area-templates Project templates, Item Templates for Blazor and MAUI platform/windows 🪟 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed t/bug Something isn't working t/desktop The issue relates to desktop scenarios (MacOS/MacCatalyst/Windows/WinUI/WinAppSDK)
Milestone

Comments

@vsfeedback
Copy link

vsfeedback commented Jan 13, 2023

This issue has been moved from a ticket on Developer Community.

No title on title bar nor on task bar
Title only appears inside the application, on the top of NavigationPage or of Shell

image

@mattleibow
Copy link
Member

This is most likely related to #11263

@mattleibow
Copy link
Member

Seems the Title is not bubbled up, but thisis also partially by design as some apps do not wish the APP title to match the current page.

If you do, you could maybe put something like this in your shell code-behind (AppShell.xaml.cs):

protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
    base.OnPropertyChanged(propertyName);

    if (propertyName == WindowProperty.PropertyName)
        Window?.SetBinding(Window.TitleProperty, new Binding("CurrentItem.Title", source: this) { StringFormat = ".NET MAUI {0}" });
}

If you want a fixed title for the app, then this is also possible if you put this in your app code-behind (App.xaml.cs):

protected override Window CreateWindow(IActivationState activationState)
{
    var window = base.CreateWindow(activationState);
    window.Title = ".NET MAUI";
    return window;
}

@mattleibow mattleibow added the s/needs-info Issue needs more info from the author label Jan 16, 2023
@ghost
Copy link

ghost commented Jan 16, 2023

Hi @vsfeedback. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@PureWeen
Copy link
Member

I think this needs a repro

  1. if you're using Shell just set the Title on the AppShell.
<Shell
    x:Class="MauiApp3.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:MauiApp3"
    Shell.FlyoutBehavior="Disabled"
    Title="Maui APP">
  1. if you're not using shell then follow @mattleibow 's example
protected override Window CreateWindow(IActivationState activationState)
{
    var window = base.CreateWindow(activationState);
    window.Title = ".NET MAUI";
    return window;
}

@BrandonStudio
Copy link

@mattleibow I think this binding should be the built-in behaviour

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Jan 17, 2023
@PureWeen
Copy link
Member

@BrandonStudio what behavior?

You should be able to use all the available APIs to achieve what you need to.

@PureWeen PureWeen added s/needs-info Issue needs more info from the author and removed s/needs-attention Issue has more information and needs another look labels Jan 17, 2023
@ghost
Copy link

ghost commented Jan 17, 2023

Hi @vsfeedback. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@BrandonStudio
Copy link

@PureWeen what you have said in #11263 (comment).
The windows should have default titles which are same as Shell title or have partterns like %ShellTitle% - %AppName% just like most Windows applications. Even if not all developers hope to use this, most people do.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Jan 18, 2023
@rachelkang rachelkang added s/needs-info Issue needs more info from the author and removed s/needs-attention Issue has more information and needs another look labels Jan 18, 2023
@ghost
Copy link

ghost commented Jan 18, 2023

Hi @vsfeedback. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@PureWeen
Copy link
Member

@PureWeen what you have said in #11263 (comment). The windows should have default titles which are same as Shell title

It currently already does this with Shell. The Shell.Title property propagates to the Window Title. So, you can change Shell.Current.Title as you navigate or you inside each page you could do Window.Title = as you navigate around pages.

or have partterns like %ShellTitle% - %AppName% just like most Windows applications. Even if not all developers hope to use this, most people do.

I don't think we can provide a default title arrangement based on current page/window title. Everyone will have different requirement for setting the title.

@BrandonStudio
Copy link

As you say, there is no problem on title?
Then why I have the above problem? Is that because I'm using NavigationPage instead of Shell?

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Jan 19, 2023
@Eilon Eilon added the legacy-area-desktop Windows / WinUI / Project Reunion & Mac Catalyst / macOS specifics (Menus & other Controls)) label Jan 19, 2023
@mattleibow
Copy link
Member

mattleibow commented Jan 26, 2023

@BrandonStudio not sure what you are setting to see the issue. If you are using the NavigationPage then you will need to set Window.Title = xxx in the navigation page. Or you can do a binding like this:

protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
    base.OnPropertyChanged(propertyName);

    if (propertyName == WindowProperty.PropertyName)
        Window?.SetBinding(Window.TitleProperty, new Binding("CurrentPage.Title", source: this) { StringFormat = ".NET MAUI {0}" });
}

In order for a more dynamic title, you will have to add the binding. We can't really set some defaults as this is often very different per app. Some one a static title on the Window because the app is not a document based. Others want <appname> - <pagename>. Some want <pagename> - <appname>. Some may even want to use some way to indicate that something is not yet saved (like some asterisk).

@mattleibow mattleibow added s/needs-info Issue needs more info from the author and removed s/needs-attention Issue has more information and needs another look labels Jan 26, 2023
@dotnet dotnet deleted a comment Jan 26, 2023
@BrandonStudio
Copy link

@mattleibow What I meant by "default" is that the title shows (not empty) without manually configuration.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Jan 27, 2023
@PureWeen PureWeen changed the title (.NET MAUI Windows) application window does not have a title Update .NET MAUI template to provide a window with a default title set Jan 27, 2023
@PureWeen
Copy link
Member

@BrandonStudio I don't think automatically propagating the default title up would be a safe move. Anytime that you add default behavior it's tricky for users to unwind. What if you want a blank title? I updated the description on here so we can update our templates to include a window approach which I think will be more discoverable for people.

Maybe we add that code into the templates?

@PureWeen PureWeen added the area-templates Project templates, Item Templates for Blazor and MAUI label Jan 27, 2023
@PureWeen PureWeen added this to the Backlog milestone Jan 27, 2023
@ghost
Copy link

ghost commented Jan 27, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@jinxinjuan jinxinjuan added the s/triaged Issue has been reviewed label Aug 16, 2023
@jinxinjuan
Copy link
Collaborator

Could you share us a sample project to repro this issue? Thanks.

@jfversluis
Copy link
Member

I think this has been fixed in the meantime.

@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2024
@Eilon Eilon added t/desktop The issue relates to desktop scenarios (MacOS/MacCatalyst/Windows/WinUI/WinAppSDK) and removed legacy-area-desktop Windows / WinUI / Project Reunion & Mac Catalyst / macOS specifics (Menus & other Controls)) labels May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-templates Project templates, Item Templates for Blazor and MAUI platform/windows 🪟 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed t/bug Something isn't working t/desktop The issue relates to desktop scenarios (MacOS/MacCatalyst/Windows/WinUI/WinAppSDK)
Projects
None yet
Development

No branches or pull requests

9 participants