dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.05k stars 1.73k forks source link

[WinUI] Styles from a `ResourceDictionary` do not work on WinUI #16050

Open AndreasReitberger opened 1 year ago

AndreasReitberger commented 1 year ago

Description

I'm facing a strange issue. All my styles are working fine on Android / iOS, however look odd once I run it on Windows. It gets recognizable when running the app on dark mode Ref: https://github.com/AndreasReitberger/SharedMauiXamlStyles/issues/173

I made a small repro.

<HorizontalStackLayout
    HorizontalOptions="Center"
    >
    <CheckBox
        />
    <Label
        VerticalTextAlignment="Center"
        Text="Click me to see that the color settings from the Style.xaml doesn't work"
        />
</HorizontalStackLayout>

Windows: image

Android: image

Steps to Reproduce

  1. Run the app on Windows
  2. Click the CheckBox
  3. See that the check icon is not visable
  4. Run it on Android and verify the same
  5. Same is with an Editor, the line should be actually the PrimaryColor, but this is not the case on WinUI

Link to public reproduction project repository

https://github.com/AndreasReitberger/MauiAppWinUIStyleIssue

Version with bug

7.0.49

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

windows10.0.19041.0

Did you find any workaround?

No response

Relevant log output

No response

AndreasReitberger commented 1 year ago

I'm not sure if this is relevant, but I get this warnings and errors in the output window.

Microsoft.Maui.Controls.Element: Warning: Microsoft.Maui.Controls.SolidColorBrush is already a child of Microsoft.Maui.Controls.ContentView. Remove Microsoft.Maui.Controls.SolidColorBrush from Microsoft.Maui.Controls.ContentView before adding to Microsoft.Maui.Controls.ContentView. Microsoft.Maui.Controls.BindableObject: Warning: Cannot convert Microsoft.Maui.Controls.Internals.DynamicResource to type 'Microsoft.Maui.Graphics.Color' Microsoft.Maui.Controls.BindableObject: Warning: Cannot convert Microsoft.Maui.Controls.Internals.DynamicResource to type 'Microsoft.Maui.Graphics.Color' Ausnahme ausgelöst: "System.NotSupportedException" in System.ComponentModel.TypeConverter.dll Ausnahme ausgelöst: "System.Collections.Generic.KeyNotFoundException" in Microsoft.Maui.Controls.dll Ausnahme ausgelöst: "System.Collections.Generic.KeyNotFoundException" in Microsoft.Maui.Controls.dll Ausnahme ausgelöst: "System.Collections.Generic.KeyNotFoundException" in Microsoft.Maui.Controls.dll Ausnahme ausgelöst: "System.Collections.Generic.KeyNotFoundException" in Microsoft.Maui.Controls.dll Ausnahme ausgelöst: "System.Collections.Generic.KeyNotFoundException" in Microsoft.Maui.Controls.dll

_

ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

mattleibow commented 1 year ago

This seems to be the issue maybe?

Microsoft.Maui.Controls.BindableObject: Warning: Cannot convert Microsoft.Maui.Controls.Internals.DynamicResource to type 'Microsoft.Maui.Graphics.Color'

Or this?

Ausnahme ausgelöst: "System.Collections.Generic.KeyNotFoundException" in Microsoft.Maui.Controls.dll

AndreasReitberger commented 1 year ago

But it only happens in Windows, Android works fine with the same code.

AndreaGobs commented 1 year ago

same issue for me only on Windows

XamlTest commented 1 year ago

Verified this on Visual Studio Enterprise 17.7.0 Preview 6.0. Repro on Windows 11 .NET 8, not repro on Android 13.0-API33 and iOS 16.4 with below Project: MauiAppWinUIStyleIssue.zip

AndreasReitberger commented 1 year ago

Issue still exists in RC2

AndreasReitberger commented 8 months ago

Issue still exists in 8.0.7

AndreasReitberger commented 7 months ago

Seems to be fixed in 8.0.10. Can somebody else confirm? If so, I'll close the issue.

image

It only seems not to be possible to change the color of the Check icon?