microsoft / microsoft-ui-xaml

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

Binding properties of type `Thickness` in `Resource` crashes the app #10078

Open HO-COOH opened 5 days ago

HO-COOH commented 5 days ago

Describe the bug

Binding properties of type Thickness, like Margin and Padding in Resource will cause the app to crash. The crash happens before the getter of the binding is even called.

I thought it might be unsupported, but using the same way to bind Color does work. So there might be an issue here.

Steps to reproduce the bug

  1. Create a new WinUI3 C++ packaged project
  2. In MainWindow.xaml, use this xaml

    <StackPanel Orientation="Horizontal">
        <StackPanel.Resources>
            <Style
                x:Key="MyButtonStyle"
                BasedOn="{StaticResource AccentButtonStyle}"
                TargetType="Button">
    
                <Setter Property="Margin" Value="{x:Bind MyPadding, Mode=OneWay}" />
            </Style>
        </StackPanel.Resources>
        <Button Style="{StaticResource MyButtonStyle}">Click Me</Button>
    </StackPanel>
  3. In code-behind, return random values for the binding
    winrt::Microsoft::UI::Xaml::Thickness MyPadding() { return {1,2,3,4}; }

Expected behavior

No response

Screenshots

Image

NuGet package version

WinUI 3 - Windows App SDK 1.6.1: 1.6.240923002

Windows version

Windows 11 (22H2): Build 22621

Additional context

Image Repro

kmgallahan commented 5 days ago

Possibly due to ResourceDictionary sharable types limitation, but not sure:

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