gpt4 book ai didi

uwp - 组合框的默认选定索引使我的 UWP 应用程序崩溃

转载 作者:行者123 更新时间:2023-12-04 14:25:12 28 4
gpt4 key购买 nike

为什么默认选择的索引不起作用?它因平台异常而崩溃:

<ComboBox x:Name="dCmbControl" x:Uid="dCmbControl" SelectionChanged="ComboBox_SelectionChanged" SelectedIndex="0" ItemsSource="{x:Bind abc}"/>

RumTime 错误:

Exception thrown at 0x00007FFDEF7F7788 (KernelBase.dll) in abc.exe: 0x40080201: WinRT originate error (parameters: 0x00000000802B000A, 0x000000000000003E, 0x00000066746FBB90).
Exception thrown at 0x00007FFDEF7F7788 in abc.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x00000066746FC0E0. HRESULT:0x802B000A The text associated with this error code could not be found.

我做错了什么?

最佳答案

SelectedIndex 设置为 0 时,ComboBox 尝试访问其第一个子项以选择它。加载 XAML 时,将构建控件并将 SelectedIndex 初始化为 0。这将更新相关的 SelectedItem 属性,但由于此时仍然没有可用的项目, 引发异常。

不幸的是,引发的异常不包含任何相关细节(在 C# 中也是如此)。

您可以在 XAML 中将该值设置为 -1,并在加载组合框后将其更新为您想要的值(通过隐藏代码或通过绑定(bind))。

关于uwp - 组合框的默认选定索引使我的 UWP 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47177687/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com