XAML Metro 应用程序中的数据绑定时出现 ComException

发布于 2025-01-01 08:56:28 字数 1858 浏览 2 评论 0原文

将 ListView 绑定到列表项时出现 COM 异常。异常是从这里的第二行抛出的。 “app.exe 中发生了类型为‘System.Runtime.InteropServices.COMException’的第一次机会异常

附加信息:灾难性故障(来自 HRESULT 的异常:0x8000FFFF (E_UNEXPECTED))”

Playlists = content.getPlayLists();
PlayListView.DataContext = Playlists;

声明绑定的 XAML

<ListView x:Name="PlayListView" ItemsSource="{Binding ElementName=Playlists}" Background="AntiqueWhite" SelectionChanged="PlayListView_SelectionChanged" HorizontalAlignment="Left" Height="364" Margin="56,268,0,0" VerticalAlignment="Top" Width="308">
        <ListView.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Path=Name}"/>
                </StackPanel>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

我通过仅使用 2 个字符串简化了播放列表但仍然有同样的问题。

public class PlayList
{
    private string playListName;
    private string description;
    private DateTime dateTimeCreated;
    private int numTracks;
    private List<Track> tracks;
    private string id;

    public string Name
    {
        get { return playListName; }
        set { playListName = value; }
    }

    public string Description
    {
        get { return description; }
        set { description = value; }
    }

    public DateTime CreatedDate
    {
        get { return dateTimeCreated; }
        set { dateTimeCreated = value; }
    }

    public int NumberOfTracks
    {
        get { return numTracks; }
        set { numTracks = value; }
    }

    public List<Track> Tracks
    {
        get { return tracks; }
        set { tracks = value; }
    }

    public String Id
    {
        get { return id; }
        set { id = value; }
    }
}

I am getting a COM Exception while binding ListView to a List items. The Exception is being thrown from the 2nd line here. "A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in app.exe

Additional information: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"

Playlists = content.getPlayLists();
PlayListView.DataContext = Playlists;

XAML declaring the binding

<ListView x:Name="PlayListView" ItemsSource="{Binding ElementName=Playlists}" Background="AntiqueWhite" SelectionChanged="PlayListView_SelectionChanged" HorizontalAlignment="Left" Height="364" Margin="56,268,0,0" VerticalAlignment="Top" Width="308">
        <ListView.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Path=Name}"/>
                </StackPanel>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

I simplified the PlayList by just having 2 strings but still has the same issue.

public class PlayList
{
    private string playListName;
    private string description;
    private DateTime dateTimeCreated;
    private int numTracks;
    private List<Track> tracks;
    private string id;

    public string Name
    {
        get { return playListName; }
        set { playListName = value; }
    }

    public string Description
    {
        get { return description; }
        set { description = value; }
    }

    public DateTime CreatedDate
    {
        get { return dateTimeCreated; }
        set { dateTimeCreated = value; }
    }

    public int NumberOfTracks
    {
        get { return numTracks; }
        set { numTracks = value; }
    }

    public List<Track> Tracks
    {
        get { return tracks; }
        set { tracks = value; }
    }

    public String Id
    {
        get { return id; }
        set { id = value; }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白色秋天 2025-01-08 08:56:28

该问题是由于未在主线程上设置 UI 元素造成的。我用它修复了

PlayListView.Dispatcher.Invoke(Windows.UI.Core.CoreDispatcherPriority.Normal, (s, a) => 
{ 
    PlayListView.DataContext = Playlists; 
}, PlayListView, null);

The problem is due to not setting the UI element on main thread. I fixed it using

PlayListView.Dispatcher.Invoke(Windows.UI.Core.CoreDispatcherPriority.Normal, (s, a) => 
{ 
    PlayListView.DataContext = Playlists; 
}, PlayListView, null);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文