呈现许多复选框时发生Microsoft.UI.Xaml.Markup.XamlParseException异常

8mmmxcuj  于 2023-01-18  发布在  其他
关注(0)|答案(1)|浏览(108)

我在WinUI3上工作。当执行下面的代码并呈现CheckBox时,会发生UnhandledException。

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
当像下面的代码那样修改时,它可以正常工作。

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

或者,将CheckBox更改为Button也可以正常工作。

<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>

我已经尝试了很多事情,并猜测它,它似乎发生时,有许多复选框。
是否存在与此相关的问题或解决方案?

jljoyd4f

jljoyd4f1#

这可能与此issue有关,它应该是固定的。

    • TLTR**:这似乎只是CheckBoxes的一个问题,目前似乎没有解决方法。因此,请再次考虑这是否是您真正需要的。

我尝试了一些东西,这是我发现(至少在我的笔记本电脑):
CheckBoxes

  • 可以在主窗口中示例化的最大数目。(尚未在Pages中尝试。):
  • WinAppSDK版本1.1:286项
  • WinAppSDK版本1.2:563项
  • 即使您将CheckBoxes分隔到不同的Grids中,也会遇到异常(尚未尝试不同的Pages)。

ButtonsToggleButtons、偶数Expanders

  • 您可以示例化10,000个以上的项而不会发生异常。

相关问题