unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.88k stars 717 forks source link

`Storyboards` are always null in Uno.WinUI on MacOS #5359

Closed vadd98 closed 4 months ago

vadd98 commented 3 years ago

Current behavior

I put a storyboard in my xaml and I start it from code-behind. When the animation begins I always get the error "Object not set to an instance of an object". Debugging the page it is possible to see that the storyboard is actualy null.

Expected behavior

Being able to use storyboards.

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

1) Insert a stroyboard in the resources of a xaml (in my case, in ) 2) Write the animation that will animate controls in the same xaml 3) In code-behind launch the animation (Storyboard.Begin());

Workaround

None

Environment

Nuget Package:

Nuget Package Version(s): Uno.WinUI 3.5.0

Affected platform(s):

IDE:

Relevant plugins:

Anything else we need to know?

jeromelaban commented 3 years ago

Thanks for the report. Could you attach a small repro sample that demonstrates the issue (using an Uno app template), thanks !

vadd98 commented 3 years ago

Sure, here you are a repro https://github.com/vadd98/ReproApp/ In MainPage there are two ellipses and a button to enable the animation of the rear ellipse. While I was writing the repro I think to have found the bug: in the storyboard I set a color using a ThemeResource. If I replace the ThemeResource with a standard color and build again, the storyboard is not anymore null and starts to work. By the way I'm developing an app that relies on ThemeResource because it has a light and a dark theme. Is there a way to make ThemeResource work in storyboards?

GitHub
vadd98/ReproApp
Contribute to vadd98/ReproApp development by creating an account on GitHub.
jeromelaban commented 3 years ago

cc @davidjohnoliver

davidjohnoliver commented 2 years ago

cc @dr1rrb ?

dr1rrb commented 2 years ago

Got a look to the repro, it really seems it's a bug in the resource resolution.

The Storyboard is generated (when building on windows):

                Resources = {
                ["ButtonAnimation"] = 
                new global::Uno.UI.Xaml.WeakResourceInitializer(this, __ResourceOwner_0 => 
                    new global::Microsoft.UI.Xaml.Media.Animation.Storyboard
                    {
                        // Source ..\..\..\..\..\..\..\ReproApp.Shared\MainPage.xaml (Line 6:14)
                        Children = 
                        {
                            new global::Microsoft.UI.Xaml.Media.Animation.DoubleAnimation
                            {
                                AutoReverse = true/* bool/, True, DoubleAnimation/AutoReverse */,
                                From = 1d/* double/, 1, DoubleAnimation/From */,
                                To = 1.10d/* double/, 1.10, DoubleAnimation/To */,
                                Duration = new Duration(global::System.TimeSpan.FromTicks(20000000 /* 0:0:2 */))/* Microsoft.UI.Xaml.Duration/, 0:0:2, DoubleAnimation/Duration */,
                                RepeatBehavior = @"Forever"/* Microsoft.UI.Xaml.Media.Animation.RepeatBehavior/, Forever, DoubleAnimation/RepeatBehavior */,
                                // Source ..\..\..\..\..\..\..\ReproApp.Shared\MainPage.xaml (Line 7:18)
                            }

but I would assume that it's not materialized so the ButtonAnimation property is never assigned:

                    .MainPage_b739431385094e22625aa44b70ba9e1a_XamlApply((MainPage_b739431385094e22625aa44b70ba9e1aXamlApplyExtensions.XamlApplyHandler2)(c3 => 
                    {
                        nameScope.RegisterName("ButtonAnimation", c3);
                        this.ButtonAnimation = c3;
                    }

So yes Jérôme mentioned the right David @davidjohnoliver, giving it back to you :)

MartinZikmund commented 4 months ago

This is no longer relevant as we have a new macOS backend 🚀