I noticed after upgrading Visual Studio to 17.5.1 from 17.4.4 that images were no longer showing up in my CollectionView items consistently. Some of them may show, but it seems somewhat random how many will show, if at all. I'm using a svg image file in my resources.
After rolling back to 17.4, it worked fine. I waited until 17.5.2 was released and still have the same issue. I just made some simple modifications to the MAUI sample project "MauiApp2".
I changed the .csproj project file to build to a folder (unpackaged non-MSIX):
In the .csproj file
<!-- This was added -->
<WindowsPackageType>None</WindowsPackageType>
My "launchSettings.json"
{
"profiles": {
"Windows Machine": {
"commandName": "Project", <-- Changed this from "MsixPackage" to "Project"
"nativeDebugging": false,
"hotReloadEnabled": false
}
}
}
Modified the "CollectionView" in MainPage to show a label and an image button referencing the image from resources:
<CollectionView Grid.Row="2" Grid.ColumnSpan="2"
ItemsSource="{Binding Items}"
SelectionMode="None">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="{x:Type x:String}">
<Grid Padding="0,5">
<Frame>
<HorizontalStackLayout>
<Label Text="{Binding .}"
FontSize="18" />
<ImageButton Source="{AppThemeBinding Dark=refresh_pink.png, Light=refresh_pink.png}"
HeightRequest="32"
ToolTipProperties.Text="This image only shows up some of the time"/>
</HorizontalStackLayout>
</Frame>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
I added a collection to the MainViewModel to bind to ItemsSource
:
public MainViewModel()
{
Items = new ObservableCollection<string>();
AddABunchOfThings();
}
private void AddABunchOfThings()
{
Items.Add("One");
Items.Add("Two");
Items.Add("Three");
Items.Add("Four");
Items.Add("Five");
Items.Add("Six");
Items.Add("Seven");
Items.Add("Eight");
Items.Add("Nine");
Items.Add("Ten");
}
[ObservableProperty]
ObservableCollection<string> items;
That's pretty much it. Images load consistently in 17.4.4, but from 17.5.1 it consistently fails to show the images. In the screenshot below, the image displayed properly for just one of the items.