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

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    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”>
                <xcdg:DataGridControl.Resources>
              

                    <Style TargetType=“xcdg:DataRow”>
                        

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

                   </Style>
                    

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

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

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

                   </Style>
               

               </xcdg:DataGridControl.Resources>
               

               <xcdg:DataGridControl.View>
                    

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

                        <xcdg:TableView.FixedHeaders>
                            

                               <DataTemplate>      

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

                               <DataTemplate>
                                

                                       <xcdg:ColumnManagerRow/>
                           

                              </DataTemplate>
                       

                        </xcdg:TableView.FixedHeaders>
                    

                    </xcdg:TableView>
               

                 </xcdg:DataGridControl.View>

               

                 <xcdg:DataGridControl.Columns>
                    

                    <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” />

                </xcdg:DataGridControl.Columns>

            

    </xcdg:DataGridControl>

     

    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 =>
            e.AsyncQueryInfo.EndQuery(models.ToArray()));
        }
     
        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. 
     
    Regards,
    Yuliya 

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

    Fawzi [Xceed]
    Member
    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)

    chaperona
    Keymaster
    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.