-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
App Icon doesn't appear in window title bar #20265
Comments
As far as I'm aware, for the current version of the TitleBar, it's never supported that. Reading the documentation that field is for the package icon (Used in the start menu, etc), not for a window icon. By default, WinUI 3 apps look like this. The default AppWindow bar uses the Windows title bar, which includes an icon. But this icon isn't set by WinUI, even though it includes a package icon To change it, you would need to set it. However, MAUI doesn't use the default Windows toolbar, it extends the baseline Window into it. This implementation includes an app name, but no icon. That said, maui/src/Core/src/Platform/Windows/MauiWinUIWindow.cs Lines 183 to 200 in a01e1ee
They do pinvoke into Win32 and set the AppIcon. But this icon will only appear if you disable the Extended toolbar. This is not the default behavior, and I don't think there is a MAUI API to do this AFAIK. You would need to know how to access the handler and call that bool yourself. And it would also break any TitleBar customization you have, since it's not the title bar. I would need to look through the history more, but my guess is that for net6.0, MAUI either didn't use But, for the existing titlebar, AFAIK, it doesn't have a way to set that icon yourself. I could be missing something, but I think that would need to be a feature to be added. @PureWeen what do you think? |
You see what I just said above? Yeah, I was wrong, this is a bug maui/src/Core/src/Platform/Windows/Styles/WindowRootViewStyle.xaml Lines 22 to 29 in a01e1ee
That's the default template for the titlebar. It's linking to an icon that doesn't exist in the package. @ThanhHaiDang96 if you go into your <maui:MauiWinUIApplication.Resources>
<DataTemplate x:Key="MauiAppTitleBarTemplate">
<Border
Canvas.ZIndex="1"
VerticalAlignment="Stretch"
Margin="0,0,0,0">
<StackPanel Orientation="Horizontal" Margin="12, 0, 0, 0" x:Name="RootStackPanel">
<Image
x:Name="AppFontIcon"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Source="{YOUR APPICON NAME HERE}Logo.png"
Visibility="Visible"
Width="16"
Height="16"/>
<TextBlock
x:Name="AppTitle"
VerticalAlignment="Center"
Margin="{Binding WindowTitleMargin}"
Text="{Binding WindowTitle}"
Foreground="{Binding WindowTitleForeground}"
Style="{StaticResource CaptionTextBlockStyle}" />
</StackPanel>
</Border>
</DataTemplate>
</maui:MauiWinUIApplication.Resources> Replace That's what an extra 5 minutes of searching gets me. |
Duplicate of #6908 |
@ThanhHaiDang96 as an alternative, you just need an image with the name Ex: |
Description
Hi, I'm using MAUI to create an application which's running on Windows and Mac platform.
In my main page, I have a button. And when button is clicked, another window appears.
I set the icon app in .csproj file:
However, the icon doesn't appear in title bar in all of windows of this app.
My Button clicked handler:
How can I show the icon in window title bar? Specially, in the secondary window.
Steps to Reproduce
Link to public reproduction project repository
No response
Version with bug
8.0.6
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android, Windows, macOS
Affected platform versions
No response
Did you find any workaround?
Nothing
Relevant log output
No response
The text was updated successfully, but these errors were encountered: