microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.2k stars 669 forks source link

Why does it needs a String to bind to a `Windows.Foundation.TimeSpan` in XAML resource? #9798

Open HO-COOH opened 2 weeks ago

HO-COOH commented 2 weeks ago

Describe the bug

"Obviously", this is the correct way of binding BeginTime to a xaml resource

    <Grid x:Name="RootGrid">
        <Grid.Resources>
            <x:String x:Key="MyBeginTime">0:0:1</x:String>
        </Grid.Resources>

        <Grid.Triggers>
            <EventTrigger>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Opacity"
                                         BeginTime="{StaticResource MyBeginTime}"
                                         From="0"
                                         To="1"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Grid.Triggers>
    </Grid>

Note: You got absolutely no intellisense when you type out the StaticResource binding (which is usually an indication of you doing something stupid)

Using a sys:TimeSpan gives a runtime error in C# project and a build time error in C++ project: C#: image C++: 1db0503a2907008100d7327a846d8352

Using a x:TimeSpan gives a build error in both: image

This behavior is so unexpected and is documented NOWHERE.

Steps to reproduce the bug

Just see above.

Expected behavior

No response

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.5.4: 1.5.240607001

Windows version

Windows 11 (22H2): Build 22621

Additional context

No response

kmgallahan commented 2 weeks ago

This behavior is so unexpected and is documented NOWHERE.

https://learn.microsoft.com/en-us/windows/apps/design/style/xaml-resource-dictionary#xaml-resources-must-be-shareable

https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.resourcedictionary?view=windows-app-sdk-1.5#shareable-types-and-uielement-types

https://learn.microsoft.com/en-us/windows/uwp/xaml-platform/xaml-intrinsic-data-types

Note Dates and times (properties that use DateTime or DateTimeOffset, TimeSpan or System.TimeSpan) aren't settable with a XAML primitive.

HO-COOH commented 2 weeks ago

This behavior is so unexpected and is documented NOWHERE.

https://learn.microsoft.com/en-us/windows/apps/design/style/xaml-resource-dictionary#xaml-resources-must-be-shareable

https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.resourcedictionary?view=windows-app-sdk-1.5#shareable-types-and-uielement-types

https://learn.microsoft.com/en-us/windows/uwp/xaml-platform/xaml-intrinsic-data-types

Note Dates and times (properties that use DateTime or DateTimeOffset, TimeSpan or System.TimeSpan) aren't settable with a XAML primitive.

“aren't settable with a XAML primitive.” and this is already obviously wrong or out-dated, I can set it as a xaml string.