uno.toolkit.ui icon indicating copy to clipboard operation
uno.toolkit.ui copied to clipboard

Using a style that uses the ResourceExtensions works only for the first element using it

Open ArchieCoder opened this issue 1 year ago • 19 comments

Current behavior

image

Expected behavior

Same blue background for both buttons

How to reproduce it (as minimally and precisely as possible)

UnoApp1.zip

The only difference is I don't use BasedOn in my Style

<Page
    x:Class="UnoApp1.Presentation.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:utu="using:Uno.Toolkit.UI"
    Background="Black"
    NavigationCacheMode="Required">

    <Page.Resources>

        <SolidColorBrush x:Key="ActionBackgroundBrush">
            #2398CB
        </SolidColorBrush>

        <SolidColorBrush x:Key="ActionForegroundBrush">
            #FFFFFF
        </SolidColorBrush>

        <SolidColorBrush x:Key="Gray300Brush">
            #D0D5DD
        </SolidColorBrush>

        <Style x:Key="ActionButtonStyle" TargetType="Button">
            <Setter Property="CornerRadius" Value="8" />
            <Setter Property="utu:ResourceExtensions.Resources">
                <Setter.Value>
                    <ResourceDictionary>
                        <ResourceDictionary.ThemeDictionaries>
                            <ResourceDictionary x:Key="Default">
                                <StaticResource x:Key="ButtonBackground" ResourceKey="ActionBackgroundBrush" />
                                <StaticResource x:Key="ButtonForeground" ResourceKey="ActionForegroundBrush" />
                                <StaticResource x:Key="ButtonBackgroundPointerOver" ResourceKey="Gray300Brush" />
                                <StaticResource x:Key="ButtonBackgroundPressed" ResourceKey="ActionBackgroundBrush" />
                            </ResourceDictionary>
                        </ResourceDictionary.ThemeDictionaries>
                    </ResourceDictionary>
                </Setter.Value>
            </Setter>
        </Style>

    </Page.Resources>

    <StackPanel
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        Orientation="Horizontal">

        <Button Content="Menu" Style="{StaticResource ActionButtonStyle}" />

        <Button
            Margin="12,0,0,0"
            Content="Menu 2"
            Style="{StaticResource ActionButtonStyle}" />

    </StackPanel>

</Page>

Workaround

No response

Works on UWP/WinUI

No

Environment

No response

NuGet package version(s)

No response

Affected platforms

No response

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

ArchieCoder avatar Jul 12 '24 18:07 ArchieCoder

cc @kazo0

ArchieCoder avatar Jul 12 '24 18:07 ArchieCoder

@ArchieCoder if you add the BasedOn="{StaticResource DefaultButtonStyle}" then it should At least for the net8.0-desktop target, I will try with windows as well

kazo0 avatar Jul 12 '24 20:07 kazo0

Adding BasedOn="{StaticResource DefaultButtonStyle}" works for net8.0, but it does not work for WinUI.

ArchieCoder avatar Jul 12 '24 20:07 ArchieCoder

ArgumentException: Value does not fall within the expected range.
call-stack:
	00 UnoApp1.Presentation.MainPage.MainPage() Line 7
	01 UnoApp1.Presentation.MainPage.InitializeComponent() Line 41
	02 Microsoft.UI.Xaml.Application.LoadComponent(object component, System.Uri resourceLocator, Microsoft.UI.Xaml.Controls.Primitives.ComponentResourceLocation componentResourceLocation) Line 324
	03 ABI.Microsoft.UI.Xaml.IApplicationStaticsMethods.LoadComponent(WinRT.IObjectReference _obj, object component, System.Uri resourceLocator, Microsoft.UI.Xaml.Controls.Primitives.ComponentResourceLocation componentResourceLocation) Line 13782
	04 [Managed to Native Transition]	
	05 [Native to Managed Transition]	
	06 ABI.Microsoft.UI.Xaml.PropertyChangedCallback.Do_Abi_Invoke(nint thisPtr, nint d, nint e) Line 26020
	07 Uno.Toolkit.UI.ResourceExtensions.OnResourcesChanged(Microsoft.UI.Xaml.DependencyObject d, Microsoft.UI.Xaml.DependencyPropertyChangedEventArgs e) Line 34
	08 Microsoft.UI.Xaml.FrameworkElement.Resources.set(Microsoft.UI.Xaml.ResourceDictionary value) Line 4337
	09 ABI.Microsoft.UI.Xaml.IFrameworkElementMethods.set_Resources(WinRT.IObjectReference _obj, Microsoft.UI.Xaml.ResourceDictionary value) Line 17611
	10 WinRT.ExceptionHelpers.ThrowExceptionForHR(int hr) Line 148
	11 WinRT.ExceptionHelpers.ThrowExceptionForHR.__Throw|39_0(int hr) Line 146

this can be repro'd with:

var rd = new ResourceDictionary();
Border1.Resources = rd;
Border2.Resources = rd;

which is exactly what we are doing here.

Xiaoy312 avatar Jul 12 '24 22:07 Xiaoy312

@Xiaoy312 Thanks for the fast follow-up. Is this fix going to be in the next official release 5.3 only?

I don't know mergify. I see backport, but I'm not sure what it means.

ArchieCoder avatar Jul 13 '24 03:07 ArchieCoder

I will let @agneszitte answer you.

Xiaoy312 avatar Jul 13 '24 06:07 Xiaoy312

@ArchieCoder yep this will be in the next stable packages of Toolkit that will be part of the overall Uno 5.3 release

kazo0 avatar Jul 15 '24 12:07 kazo0

@Xiaoy312 I cannot repro the issue with the original app in this issue, but with my app, the bug still reside.

Here is a stripped-down version of my app. Test.zip

ArchieCoder avatar Jul 24 '24 18:07 ArchieCoder

@Xiaoy312 I cannot repro the issue with the original app in this issue, but with my app, the bug still reside.

Here is a stripped-down version of my app. Test.zip

@Xiaoy312 can you take a look at the new sample that @ArchieCoder provided, please (that uses Uno.Sdk 5.3.31 that normally includes the fixes for your previous PR https://github.com/unoplatform/uno.toolkit.ui/pull/1190). Thanks in advance.

agneszitte avatar Jul 24 '24 19:07 agneszitte

@Xiaoy312 I cannot repro the issue with the original app in this issue, but with my app, the bug still reside. Here is a stripped-down version of my app. Test.zip

@Xiaoy312 can you take a look at the new sample that @ArchieCoder provided, please (that uses Uno.Sdk 5.3.31 that normally includes the fixes for your previous PR #1190). Thanks in advance.

@Kunal22shah I will let you take a look as @Xiaoy312 is busy with other tasks please

agneszitte avatar Aug 27 '24 21:08 agneszitte

@Xiaoy312 I cannot repro the issue with the original app in this issue, but with my app, the bug still reside.

Here is a stripped-down version of my app. Test.zip

Thanks @ArchieCoder for providing the zip file. I tested it with the latest 5.3.99 Uno SDK and it seem to work as expected, can you please confirm : image

Kunal22shah avatar Aug 28 '24 17:08 Kunal22shah

@Kunal22shah Did you try with Skia Desktop? With 5.3.99 and 5.4.0-dev.220, in Skia the buttons are gray not blue. image

ArchieCoder avatar Aug 28 '24 19:08 ArchieCoder

@ArchieCoder i ran the desktop WSL, it good for 5.3.99: RE-rest

Kunal22shah avatar Aug 29 '24 13:08 Kunal22shah

@Kunal22shah I added more style files from my project and I'm able to repro the issue.

Here is the new sample app: App1Updated.zip

ArchieCoder avatar Aug 29 '24 14:08 ArchieCoder

@Kunal22shah I added more style files from my project and I'm able to repro the issue.

Here is the new sample app: App1Updated.zip

Thank you a lot @ArchieCoder for the sample, @Kunal22shah will be able to investigate.

agneszitte avatar Aug 29 '24 23:08 agneszitte

@ArchieCoder Thanks again, can you double check the app you shared, I don't see the buttons on WSL now: image vs desktop: image

Kunal22shah avatar Sep 04 '24 15:09 Kunal22shah

@Kunal22shah In WSL, I do not see the buttons as well. If you remove "Style="{StaticResource ActionButtonStyle}", you will see the buttons. The bug seems then worse in Linux. This is just a page with 2 buttons.

ArchieCoder avatar Sep 04 '24 15:09 ArchieCoder

@ArchieCoder So upon investigation, it seems like its a uno bug and i have created this issue for the samehttps://github.com/unoplatform/uno/issues/18132. For now i would suggest the follow workaround to you:

For WinAppSDK : using latest toolkit version will fix it - <UnoToolkitVersion>6.2.0-dev.41</UnoToolkitVersion> For WSL : you will need to add BasedOn="{StaticResource DefaultButtonStyle}" to the button style in the Page resources on the MainPage.

RE-bug

Kunal22shah avatar Sep 05 '24 16:09 Kunal22shah

@Kunal22shah for the time being I will use the old style (that's the best workaround), but let me know when the bug will be resolved and I will test it. Thanks.

ArchieCoder avatar Sep 05 '24 16:09 ArchieCoder

Since the original issue of the first element being the only one having the resources overridden I will close this issue. The other issue that was discovered is being tracked by: https://github.com/unoplatform/uno/issues/18132

This one is a symptom of Uno's Generic.xaml have a different style than WinUI's Generic.xaml

Uno's generic.xaml button style: https://github.com/unoplatform/uno/blob/4dabe7d629771d24e312a9da948f24241387b167/src/Uno.UI/UI/Xaml/Style/Generic/Generic.xaml#L2898

WinUI's generic.xaml button style: https://github.com/microsoft/microsoft-ui-xaml/blob/69097129a853c65a16447aade4c82576d4724b1a/src/dxaml/xcp/dxaml/themes/generic.xaml#L5984

You can see that the WinUI default implicit Button style is using the ButtonBackground resource but the one in Uno is not

kazo0 avatar Dec 05 '24 23:12 kazo0