question

DennisArriola-3670 avatar image
1 Vote"
DennisArriola-3670 asked DennisArriola-3670 commented

DataGrid.EnableRowVirtualization is not available in UWP

Why is DataGrid.EnableRowVirtualization is not available in UWP?104222-image.png




I need this so that DataGrid wont instantiate a DataGridRow object for each data item in the bound data source.

This is the best solution to fix auto checking of checkboxes in a DataGrid when user scrolls down and up.
Unfortunately, this is not available in UWP. Is there a work around to fix auto checking of checkboxes in DataGrid when user scrolls up and down?

Thanks~

windows-uwp
image.png (51.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

NicoZhu-MSFT avatar image
0 Votes"
NicoZhu-MSFT answered DennisArriola-3670 commented

Hello, Welcome to Micorosoft Q&A,


DataGrid.EnableRowVirtualization is not available in UWP

EnableRowVirtualization, please refer document, it is desktop top DataGrid property, it is not apply to UWP DataGrid. And UWP DataGrid is enable virtualization automatically. If you want to disable checkbox auto overwrite, please binding it with specific bool property.


 <controls:DataGridTemplateColumn Header="Serach" Visibility="Collapsed">
     <controls:DataGridTemplateColumn.CellTemplate>
         <DataTemplate>
             <StackPanel Orientation="Horizontal">
                 <CheckBox Content="{Binding Name}" IsChecked="{Binding Complete}" />
             </StackPanel>
         </DataTemplate>
     </controls:DataGridTemplateColumn.CellTemplate>
 </controls:DataGridTemplateColumn>

Model Class


 public class Item :INotifyPropertyChanged 
 {
     public string Name { get; set; }
     public bool IsSearch { set; get; }
     private bool _complete;
     public bool Complete
     {
         get
         {
             return _complete;
         }
         set
         {
             _complete = value;
             OnPropertyChanged();
         }
     }
        
    
     public event PropertyChangedEventHandler PropertyChanged;
     private void OnPropertyChanged([CallerMemberName] string propertyName = null)
     {
         PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
     }
 }

If you do want to disable virtualization, you may try to place DataGrid in the ScrollViewer, please note disable virtualization will consume more memory and degrade performance.


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.












· 10
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @NicoZhu-MSFT ,

Thanks for your quick response.

I tried your first suggestion (binding specific bool property for IsCheck) however, this cause firing of the check an uncheck events resulting to auto checking/unchecking of other items again.

I already tried the second suggestion, but my concern here is that the header of the datagrid is included in scrolling. It cannot be frozen. Is there a way to free the header when scrolling down and up?

Thanks~

0 Votes 0 ·

For second suggestion, there is no better way to fix the header, because it was the part of scrollviewer content.

0 Votes 0 ·

this cause firing of the check an uncheck events resulting to auto checking/unchecking of other items again. Could you explain that ? we can't reproduce this problem.

0 Votes 0 ·

Hello @NicoZhu-MSFT ,

Thanks for your reply.
Please see more explanation on the first example :

The IsChecked property of CheckBox causes to call/fire the Checked and UnChecked event when use scrolls up and down.

104627-image.png

The binded events SelectFilesCommand and UnSelectFilesCommand set the IsSelected property of the model to True and False respectively for each item.

When items are checked and user scrolls up or down, the binded events are fired/called.
Depends on the current state of the item, e.g. item is checked, when user scrolls up/down and this item is not displayed anymore in the data grid, it will fire the UnSelectFilesCommand hence resulting to unchecking it again.

Thanks~

0 Votes 0 ·
image.png (40.2 KiB)
Show more comments