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
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?
CodePudding user response:
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
:
- The max number you can instantiate in the MainWindow. (Haven't tried in
Pages
.):- WinAppSDK v1.1: 286 items
- WinAppSDK v1.2: 563 items
- You get the exception even if you separate the
CheckBoxes
in differentGrids
. (Haven't tried differentPages
.)
Buttons
, ToggleButtons
, even Expanders
:
- You can instantiate more than 10,000 items without getting the exception.