I am using version 1.1.5 of the Windows App SDK to create a Desktop application in WinUI 3. I've created a Page on which I have a ListView that I'd like to have display information from a List of VisualStateGroup items. For some reason, I get a "Value does not fall within the expected range." error whenever the ListView loads the list.
Here's the Page:
<Page {some stuff}>
<Page.Resources>
<DataTemplate x:Key="ListViewTemplate" x:DataType="VisualStateGroup">
<TextBlock x:Name="groupName" Text="{x:Bind Name}" Margin="0,5,0,5" />
</DataTemplate>
</Page.Resources>
<Grid x:Name="ContentArea">
<ListView x:Name="LayoutRootVisualStateGroupListListView"
BorderThickness="1"
BorderBrush="{ThemeResource SystemControlForegroundBaseMediumLowBrush}"
Width="Auto"
Height="Auto"
HorizontalAlignment="Left"
ItemTemplate="{StaticResource ListViewTemplate}"
ItemsSource="{x:Bind LayoutRootVisualStateGroupList}"/>
</Grid>
</Page>
The code-behind includes the following in the class definition:
public ObservableCollection<VisualStateGroup> LayoutRootVisualStateGroupList { get; set; }
public FooPage()
{
// ...
LayoutRootVisualStateGroupList = new(VisualStateManager.GetVisualStateGroups(ShellPage.ViewModel.UILayoutRoot));
}
Parsing LayoutRootVisualStateGroupList appears to throw the error but I don't know why.
Converting the LayoutRootVisualStateGroupList to a List<string> (in code) and passing it into the ListView works. Using code to add strings to to the Items collection works:
foreach (var group in LayoutRootVisualStateGroupList) LayoutRootVisualStateGroupListListView.Items.Add(group.Name);
Might this have something to do with proper change notification? Thanks for any help.