Home Forums WPF controls Xceed DataGrid for WPF Data Virtualization using MVVM

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • User (Old forums)
    Post count: 23064
    #40944 |

    Is there any way to implement data virtualization using no code behind, but view model instead?

    I have tried the following: create instance of DataGridVirtualizingCollectionView in a view model, subscribe to QueryItems and QueryItemCount events, and then bind this instance to ItemsSource of the view model. The problem, that I experience, is that QueryItems event never occur, although QueryItemsCount succeeds, and result is set to eventArgs.


     Xaml (view):

     <xcdg:DataGridControl ItemScrollingBehavior=“Immediate” 
    ItemsSource=”{Binding Items} ReadOnly=“True”>

                    <Style TargetType=“xcdg:DataRow”>

                           <Setter Property=“Height” Value=“21” />


                   <Style TargetType=”{x:Type xcdg:GroupByControl}>

                             <Setter Property=“AllowGroupingModification” Value=“False”/>

                             <Setter Property=“Visibility” Value=“Collapsed”/>




                   <xcdg:TableView UseDefaultHeadersFooters=“False” IsAlternatingRowStyleEnabled=“True” >



                                       <xcdg:HierarchicalGroupByControl xcdg:TableView.CanScrollHorizontally=“False” AllowGroupingModification=“False”/>









                    <xcdg:Column FieldName=“Name” ReadOnly=“True” Title=“Name”/>

                    <xcdg:Column FieldName=“Type” ReadOnly=“True” Title=“Type”/>

                    <xcdg:Column FieldName=“SerialNumber” ReadOnly=“True” Title=“Serial Number” AllowSort=“True” />





    C# (ViewModel):

    public class ListViewModel
        private IDataProvider<ItemViewModel> dataProvider;
        private DataGridVirtualizingCollectionView items;
        public DataGridVirtualizingCollectionView Items
          get { return items; }
          set { items = value; }
        public ListViewModel(IDataProvider<ItemViewModel> dataProvider)
          this.dataProvider = dataProvider;
          Items = new DataGridVirtualizingCollectionView();
          Items.QueryItems += DataGridVirtualizingCollectionViewSource_QueryItems;
          Items.QueryItemCount += DataGridVirtualizingCollectionViewSource_QueryItemCount;
        private async void DataGridVirtualizingCollectionViewSource_QueryItems(object sender, QueryItemsEventArgs e)
          dataProvider.FetchData(e.AsyncQueryInfo.StartIndex, e.AsyncQueryInfo.RequestedItemCount, 
            models =>
        private async void DataGridVirtualizingCollectionViewSource_QueryItemCount(object sender, QueryItemCountEventArgs e)
          dataProvider.FetchData(models => e.Count = models.Count());
    I've also tried to use DataGridVirtualizingCollectionViewSource instead of DataGridVirtualizingCollectionView, but without any luck.
    I would appreciate some sample with MVVM implemented. 

    Imported from legacy forums. Posted by Yuliya (had 1089 views)

    Fawzi [Xceed]
    Post count: 722
    Hi Yuliya,
    Could you send us a simple stand-alone sample project which reproduces the issue so that we can do further investigation.

    Imported from legacy forums. Posted by Fawzi [Xceed] (had 391 views)

    Post count: 3

    This is a bit late to provide an answer, but it may be helpful for others.

    You need to use the constructor with the itemType parameter for this to work, e.g.:

    Items = new DataGridVirtualizingCollectionView( typeof( ItemViewModel ) );

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.