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; }
}
}
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.