You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a DataGrid with ItemSource bound to a grouped collection view. Adding a group to the bound collection fails if the DatGrid property ReadOnly = False. All works fine when IsReadOnly = True.
<Pagex:Class="WinUI3BugDemonstrator.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
xmlns:converters="using:CommunityToolkit.WinUI.UI.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:WinUI3BugDemonstrator"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:WinUI3BugDemonstrator.ViewModels"
d:DataContext="{d:DesignInstance Type=vm:MainPageViewModel}"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d"><Page.Resources><CollectionViewSourcex:Name="CollectionView"
IsSourceGrouped="True"
Source="{Binding FilteredCollection, Mode=OneWay}" /></Page.Resources><StackPanel><Buttonx:Name="GenerateDataButton" Click="GenerateDataButton_Click">
Make data and filter it!
</Button><controls:DataGridx:Name="datagrid"
Grid.Row="2"
Margin="12"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AutoGenerateColumns="False"
IsReadOnly="False" <!-- changing this to true makes it all work fine -->ItemsSource="{x:Bind CollectionView.View, Mode=OneWay}"><controls:DataGrid.Columns><controls:DataGridTemplateColumnHeader="Value X"><controls:DataGridTemplateColumn.CellTemplate><DataTemplate><TextBlockMargin="4" Text="{Binding X}" /></DataTemplate></controls:DataGridTemplateColumn.CellTemplate></controls:DataGridTemplateColumn><controls:DataGridTemplateColumnHeader="Value Y"><controls:DataGridTemplateColumn.CellTemplate><DataTemplate><TextBlockMargin="4" Text="{Binding Y}" /></DataTemplate></controls:DataGridTemplateColumn.CellTemplate></controls:DataGridTemplateColumn></controls:DataGrid.Columns></controls:DataGrid></StackPanel></Page>
Button click calls GenerateData in the view model.
Generating the data and filtering it causes an exception:
publicpartialclassMainPageViewModel:ObservableObject{privateObservableGroupedCollection<int,Vector2>rawCollection;[ObservableProperty]privateObservableGroupedCollection<int,MyData>filteredCollection;publicvoidGenerateData(){rawCollection=newObservableGroupedCollection<int,Vector2>();// Generate 10 data groupsfor(inti=0;i<10;i++){List<Vector2>groupValues=newList<Vector2>();for(intj=0;j<5;j++){groupValues.Add(newVector2(Random.Shared.Next(100),Random.Shared.Next(100)));}varorderedList=groupValues.OrderBy(vector =>vector.X);rawCollection.AddGroup(i,orderedList);}FilterData();}publicvoidFilterData(){intmaxXVal=75;intmaxYVal=80;FilteredCollection=newObservableGroupedCollection<int,MyData>();foreach(vargroupinrawCollection){List<MyData>currentGroup=newList<MyData>();foreach(varvingroup){if(v.X<=maxXVal&&v.Y<=maxYVal){currentGroup.Add(newMyData{X=v.X.ToString(),Y=v.Y.ToString()});}}FilteredCollection.AddGroup(group.Key,currentGroup);// Null Reference exception here}OnPropertyChanged(nameof(this.FilteredCollection));}}
MyData.cs only contains two string properties: X, Y.
Regression
No response
Reproducible in sample app?
This bug can be reproduced in the sample app.
Steps to reproduce
Using the minimal code example provided, set the IsReadOnly property of DataGrid to False. Click the button. See the Exception.
Expected behavior
Setting IsReadOnly = False should not cause an exception when changing the bound collection.
Screenshots
No response
Windows Build Number
Windows 10 1809 (Build 17763)
Windows 10 1903 (Build 18362)
Windows 10 1909 (Build 18363)
Windows 10 2004 (Build 19041)
Windows 10 20H2 (Build 19042)
Windows 10 21H1 (Build 19043)
Windows 11 21H2 (Build 22000)
Other (specify)
Other Windows Build number
Windows 10 22H2 (Build 19045.3324)
App minimum and target SDK version
Windows 10, version 1809 (Build 17763)
Windows 10, version 1903 (Build 18362)
Windows 10, version 1909 (Build 18363)
Windows 10, version 2004 (Build 19041)
Other (specify)
Other SDK version
No response
Visual Studio Version
2022
Visual Studio Build Number
17.7.1
Device form factor
Desktop
Nuget packages
Community.Toolkit.Mvvm (8.2.1)
Community.Toolkit.WinUI (7.1.2)
Community.Toolkit.WinUI.UI.Controls (7.1.2)
Microsoft.Windows.SDK.BuildTools (10.0.22621.756)
Microsoft.WindowsAppSDK (1.3.230724000)
Additional context
No response
Help us help you
Yes, but only if others can assist.
The text was updated successfully, but these errors were encountered:
Hello HoloMetrix, thank you for opening an issue with us!
I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌
HoloMetrix
changed the title
DataGrid Exception when bound to CollectionView and ReadOnly=False
DataGrid Exception when bound to CollectionView and IsReadOnly=False
Aug 24, 2023
Describe the bug
I have a DataGrid with ItemSource bound to a grouped collection view. Adding a group to the bound collection fails if the DatGrid property ReadOnly = False. All works fine when IsReadOnly = True.
Button click calls GenerateData in the view model.
Generating the data and filtering it causes an exception:
MyData.cs only contains two string properties: X, Y.
Regression
No response
Reproducible in sample app?
Steps to reproduce
Expected behavior
Setting IsReadOnly = False should not cause an exception when changing the bound collection.
Screenshots
No response
Windows Build Number
Other Windows Build number
Windows 10 22H2 (Build 19045.3324)
App minimum and target SDK version
Other SDK version
No response
Visual Studio Version
2022
Visual Studio Build Number
17.7.1
Device form factor
Desktop
Nuget packages
Additional context
No response
Help us help you
Yes, but only if others can assist.
The text was updated successfully, but these errors were encountered: