When I populate a ListView (or ItemsView) with the ItemsSource being a List<ApplicationModel.Package> object, a crash will sometimes happen when loading the control.
The crash chance goes up by a lot if I have an Image that uses the Package.Logo as a source.
When I triggered the control, I expected it to show all of the installed apps, their icons, etc. Which it did successfully, until I tried to scroll... which is when I was hit with the crash.
Using this code:
<ContentDialog
x:Class="Program.AllAppsList"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="TITLE"
Style="{ThemeResource DefaultContentDialogStyle}">
<Grid>
<ListView ItemsSource="{x:Bind Packages}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<!-- High crash chance with this uncommented -->
<Image Width="64" Height="64" Margin="5">
<Image.Source>
<BitmapImage UriSource="{Binding Logo, TargetNullValue='ms-appx:///Assets/fallback.png', FallbackValue='ms-appx:///Assets/fallback.png'}" />
</Image.Source>
</Image>
<StackPanel Orientation="Vertical" Margin="5">
<TextBlock Text="{Binding DisplayName, TargetNullValue='Unknown', FallbackValue='Unknown'}" FontWeight="Bold" />
<TextBlock Text="{Binding PublisherDisplayName, TargetNullValue='Unknown', FallbackValue='Unknown'}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</ContentDialog>
using Microsoft.UI.Xaml.Controls;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using Windows.ApplicationModel;
using Windows.Management.Deployment;
namespace Program
{
public sealed partial class AllAppsList : ContentDialog
{
public List<Package> Packages { get; set; } = new List<Package>();
public AllAppsList()
{
Packages = GetAllInstalledPackages();
this.DataContext = this;
this.InitializeComponent();
}
public static List<Package> GetAllInstalledPackages()
{
var pm = new PackageManager();
return pm.FindPackagesForUser(WindowsIdentity.GetCurrent().User?.Value).ToList();
}
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
}
private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
}
}
}