xamlwinrt-xamlwinui-3

A Microsoft.UI.Xaml.Markup.XamlParseException occurs when rendering many CheckBoxes


I'm working on WinUI3. An UnhandledException occurs when the code below is executed and CheckBoxes are rendered.

public List<int> Collection { get; set; }

public ViewModelConstructor()
{
    Collection = new();
    for (int i = 0; i < 100; i++)
    {
        Collection.Add(0);
    }
}
<ItemsRepeater ItemsSource="{x:Bind ViewModel.Collection}">
    <DataTemplate x:DataType="x:Int32">
        <StackPanel Orientation="Horizontal">
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
            <CheckBox/>
        </StackPanel>
    </DataTemplate>
</ItemsRepeater>
UnhandledException += (sender, e) =>
{
    if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};

// e.Message: "Failed to assign to property 'Microsoft.UI.Xaml.Controls.AnimatedIcon.Source'. [Line: 0 Position: 0]"
// e.Exception.Message: "XAML parsing failed."
// typeof(e.Exception): Microsoft.UI.Xaml.Markup.XamlParseException

result

exception

It works normally when modified like the code below.

public ViewModelConstructor()
{
    Collection = new();
    for (int i = 0; i < 30; i++)
    {
        Collection.Add(0);
    }
}

Alternatively, changing CheckBox to Button will work normally.

<ItemsRepeater ItemsSource="{x:Bind ViewModel.Collection}">
    <DataTemplate x:DataType="x:Int32">
        <StackPanel Orientation="Horizontal">
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
            <Button/>
        </StackPanel>
    </DataTemplate>
</ItemsRepeater>

I've tried many things and guessed it, it seems to happen when there are many CheckBoxes.

Is there any issue or solution related to this?


Solution

  • This might be related to this issue, which is supposed to be fixed.

    TLTR: This seems to be an issue only for CheckBoxes and there seems to be no workaround for the moment. So, think again if this is what you really need.

    I tried a few things and this is what I found (at least in my laptop):

    CheckBoxes:

    Buttons, ToggleButtons, even Expanders: