'Weird coloring when content extends into title bar
I want to write an app in WinUI 3 + C# 10 with a Navigationview extending into the title bar which works out well.
By putting a TextBlock into NavigationView.ContentOverlay I can set the title and some controls if needed.
To be able to drag the window in the remaining area I just call SetTitleBar(AObjectWithDesiredSize).
The background of the NavigationView panel and the object (which is a Grid) is set to "{ThemeResource ApplicationPageBackgroundThemeBrush}".
However, the resulting image looks something like this using light and dark mode:

As you can see the colors don't match the color of the background.
Here's the source code:
MainWindow.xaml:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="TitleBarColor" Height="44" Margin="200, 0, 0, 0" VerticalAlignment="Top" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"/>
<NavigationView Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<NavigationView.ContentOverlay>
<StackPanel Margin="100, 0, 0, 0" VerticalAlignment="Center" HorizontalAlignment="Left" Height="44" Orientation="Horizontal">
<Button Content="test"/>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="Title" Style="{ThemeResource CaptionTextBlockStyle}"/>
</StackPanel>
</NavigationView.ContentOverlay>
<NavigationView.MenuItems>
<NavigationViewItem Icon="Play" Content="Test"/>
<NavigationViewItem Icon="Play" Content="Test2"/>
<NavigationViewItem Icon="Play" Content="Test3"/>
</NavigationView.MenuItems>
</NavigationView>
</Grid>
MainWindow.xaml.cs:
public sealed partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
this.ExtendsContentIntoTitleBar = true;
this.SetTitleBar(TitleBarColor);
}
}
If i replace all "{ThemeResource ApplicationPageBackgroundThemeBrush}" with for example "WhiteSmoke", this effect becomes less apparent but is still there.
If i set the transparency of the TitleBarColor element to "Transparent" it's also still there.
When changing the Grid into a TextBlock there's also no change.
I also tried setting the color via ApplicationView.GetForCurrentView().TitleBar but this isn't supported in WinUI 3.
Does someone know why this is happening and how to fix it?
Thank you in advance!
Solution 1:[1]
I could fix it thanks to McNets comment.
I just had to edit App.xaml to this:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</ResourceDictionary.MergedDictionaries>
<StaticResource x:Key="WindowCaptionBackground" ResourceKey="ApplicationPageBackgroundThemeBrush" />
<StaticResource x:Key="WindowCaptionBackgroundDisabled" ResourceKey="ApplicationPageBackgroundThemeBrush" />
<!--<StaticResource x:Key="WindowCaptionForeground" ResourceKey="ButtonForegroundThemeBrush" />
<StaticResource x:Key="WindowCaptionForegroundDisabled" ResourceKey="ButtonDisabledForegroundThemeBrush" />-->
</ResourceDictionary>
</Application.Resources>
Solution 2:[2]
Yes. You can use a public IP address for your website.
Domain names are solely meant for us humans to better find what we are looking for in the world wide web.
example.com is easier than 93.184.216.34.
But it is not a requirement to have a domain.
Although, I want to point out that IP addresses, especially IPv4 addresses are not as static as you think. You did not provide any details, but if you are not willing to pay for a domain I guess you are using the free tier EC2 instances. If you reboot/terminate such an instance, the IPv4 is likely to change. So your website is not available under the old IPv4 address anymore. Domains solve this problem because you can just point the domain to the new IPv4 address.
Solution 3:[3]
Since you are using AWS, and seems to not mind any form of domain name, try CloudFront. It will give you a default domain name like so:
http://d111111abcdef8.cloudfront.net/
You can configure your EC2 as the origin for the CloudFront distribution. It has added benefits of DDoS and CDN too.
Solution 4:[4]
It is not required to have a domain.
When it comes to freenom i have only use for small projects, you can get a free domain as long you renew it every 12 months and if dont mind the ".tk"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | RD4 |
| Solution 2 | Jens |
| Solution 3 | Register Sole |
| Solution 4 | BoxEdition |
