Skip to content

ColorPicker sample in gallery crashing under Windows App SDK #509

Closed

Description

@Arlodotexe

Describe the bug

When running the gallery with the Wasdk head on the latest main commit, the ColorPicker sample will crash the app:

image

   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|38_0(Int32 hr)
   at ABI.Microsoft.UI.Xaml.IFrameworkElementOverridesMethods.MeasureOverride(IObjectReference _obj, Size availableSize)
   at Microsoft.UI.Xaml.FrameworkElement.MeasureOverride(Size availableSize)
   at Microsoft.UI.Xaml.FrameworkElement.Microsoft.UI.Xaml.IFrameworkElementOverrides.MeasureOverride(Size availableSize)
   at ABI.Microsoft.UI.Xaml.IFrameworkElementOverrides.Do_Abi_MeasureOverride_0(IntPtr thisPtr, Size availableSize, Size* result)

This crash does not occur under UWP.

Steps to reproduce

1. Clone the repo
2. Generate the gallery solution, include the ColorPicker component and the wasdk multitarget/head.
3. Build and deploy the wasdk gallery 
4. Navigate to the ColorPicker sample page and observe crash.

Expected behavior

No crash.

Screenshots

No response

Code Platform

  • UWP
  • WinAppSDK / WinUI 3
  • Web Assembly (WASM)
  • Android
  • iOS
  • MacOS
  • Linux / GTK

Windows Build Number

  • Windows 10 1809 (Build 17763)
  • Windows 10 1903 (Build 18362)
  • Windows 10 1909 (Build 18363)
  • Windows 10 2004 (Build 19041)
  • Windows 10 20H2 (Build 19042)
  • Windows 10 21H1 (Build 19043)
  • Windows 10 21H2 (Build 19044)
  • Windows 10 22H2 (Build 19045)
  • Windows 11 21H2 (Build 22000)
  • Other (specify)

Other Windows Build number

No response

App minimum and target SDK version

  • Windows 10, version 1809 (Build 17763)
  • Windows 10, version 1903 (Build 18362)
  • Windows 10, version 1909 (Build 18363)
  • Windows 10, version 2004 (Build 19041)
  • Windows 10, version 2104 (Build 20348)
  • Windows 11, version 22H2 (Build 22000)
  • Other (specify)

Other SDK version

No response

Visual Studio Version

No response

Visual Studio Build Number

No response

Device form factor

No response

Additional context

No response

Help us help you

Yes, I'd like to be assigned to work on this item.

Activity

  1. moved this to 🆕 New in Toolkit 8.xon Sep 18, 2024
  2. Arlodotexe commented on Sep 18, 2024

    @Arlodotexe
    MemberAuthor

    Has the same error message as #517

  3. Arlodotexe commented on Sep 18, 2024

    @Arlodotexe
    MemberAuthor

    Additional info uncovered thanks to a tip from @Sergio0694

    image

    (Possibly related to #516? Though, not the same error message.)

    @michael-hawker Anything you could add? SwitchPresenter may be having more than one AoT issue here.

  4. michael-hawker commented on Sep 18, 2024

    @michael-hawker
    Member

    @Arlodotexe Switch Presenter uses all the general types and such from XAML like DependencyObjectCollection and DependencyObject - It also just does a lot of general comparison/reflection-y type stuff when trying to compare values here: https://github.com/CommunityToolkit/Windows/blob/main/components/Primitives/src/SwitchPresenter/SwitchPresenter.cs#L116

    So, there's probably something there to figure out how to better guard against?

    I also saw a new issue on the WinUI repo about controls and resource dictionaries + trimming, so something we may want to keep an eye on incase there's other underlying issues still we need to be concerned about or bubble up with the platform team. RE: microsoft/microsoft-ui-xaml#10020

  5. Arlodotexe commented on Oct 17, 2024

    @Arlodotexe
    MemberAuthor

    Since #516 turned out to be an issue with the EnumValuesExtension, I suspect this may be a binding issue given the data in the exception. Could also be erroring internally in the setter, but the Value property is a good place to start looking.

  6. Arlodotexe commented on Nov 4, 2024

    @Arlodotexe
    MemberAuthor

    It looks like the problem is here:

    <controls:SwitchPresenter x:Name="ContentContainer"
    Grid.Row="2"
    Value="{Binding ElementName=ColorPanelSelector, Path=SelectedItem.Name}">

    Unfortunately, this isn't a backed resource dictionary, so we can't use x:Bind here. If we try, we get the error:

    1>V:\Windows\components\ColorPicker\src\ColorPicker.xaml(240,55): XamlCompiler error WMC1119: This Xaml file must have a code-behind class to use {x:Bind}. See http://go.microsoft.com/fwlink/?LinkID=532920&clcid=0x409 for more information
    1>Done building project "CommunityToolkit.WinUI.Controls.ColorPicker.csproj" -- FAILED.
    

    To fix the problem, we'll need to locate any .xaml files that use a non-TemplatedParent variant of {Binding}, update the resource dictionary to be backed by a cs file, and update bindings to use x:Bind.

  7. self-assigned this
    on Nov 4, 2024
  8. moved this from 🔖 Ready to 🏗 In progress in Toolkit 8.xon Nov 4, 2024
  9. michael-hawker commented on Dec 6, 2024

    @michael-hawker
    Member

    This issue got opened on the WinUI repo which is related microsoft/microsoft-ui-xaml#10214 - not too sure what we can do here atm.

  10. moved this from 🏗 In progress to 🔖 Ready in Toolkit 8.xon Apr 7, 2025
  11. AndrewKeepCoding commented on Jul 17, 2025

    @AndrewKeepCoding
    Member

    The SwitchPresenter only needs the Name of the selected item from the Segmented control. Since this Segemented control is already accessible as a TemplatedPart, why not just also include the SwitchPresenter as a TemplatedPart and implement the selection logic in code?
    That should at least prevent crashes.

  12. AndrewKeepCoding commented on Jul 17, 2025

    @AndrewKeepCoding
    Member

    Yes, it worked with a few lines of code:

    private void ColorPanelSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (this.ContentContainer is null ||
            (sender as Segmented)?.SelectedItem is not FrameworkElement selectedItem)
        {
            return;
        }
    
        this.ContentContainer.Value = selectedItem.Name;
    }

    @Arlodotexe @michael-hawker Thoughts?

  13. michael-hawker commented on Jul 18, 2025

    @michael-hawker
    Member

    Thanks @AndrewKeepCoding, I suppose that could work for now; we could add a comment pointing to the WinUI issue: microsoft/microsoft-ui-xaml#10214

  14. AndrewKeepCoding commented on Jul 19, 2025

    @AndrewKeepCoding
    Member

    Hi @michael-hawker ! Should I be assigned to create a PR for this? or can I go ahead and create one?

  15. added
    components::controls::colorpickerAn extended color picker that enables picking a color using a spectrum, sliders, or text input.
    on Aug 7, 2025
  16. moved this from 🔖 Ready to ✅ Done in Toolkit 8.xon Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingcomponents::controls::colorpickerAn extended color picker that enables picking a color using a spectrum, sliders, or text input.nativeaotThe dependency on dotnet NativeAOTregressionWhat was working is now brokesample app 🖼️

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions