This question is locked. New answers and comments are not allowed.
Hello!
I have a PagedCollectionView in my view model and RadGridView in XAML with ItemsSource binded to PagedCollectionView.
When i try to call View.SortDescriptions.Clear() inside the scope of DeferRefresh()
RadGridView fails with InvalidOperationException:
Cannot change or check the contents or current position of the PagedCollectionView while Refresh is being deferred.
Here is my xaml:
and view model:
When i commented line with
I have a PagedCollectionView in my view model and RadGridView in XAML with ItemsSource binded to PagedCollectionView.
When i try to call View.SortDescriptions.Clear() inside the scope of DeferRefresh()
RadGridView fails with InvalidOperationException:
Cannot change or check the contents or current position of the PagedCollectionView while Refresh is being deferred.
Here is my xaml:
<UserControl x:Class="RadGridViewTest.MainPage" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:local="clr-namespace:RadGridViewTest"> <UserControl.Resources> <local:MainPageViewModel x:Key="viewModel" /> </UserControl.Resources> <Grid x:Name="LayoutRoot" DataContext="{StaticResource viewModel}"> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <telerik:RadGridView ItemsSource="{Binding View}" /> <Button Grid.Row="1" Margin="5" Content="Clear sorting" Command="{Binding ClearSorting}" HorizontalAlignment="Center" /> </Grid></UserControl>and view model:
using System;using System.Collections.ObjectModel;using System.Windows;using System.Windows.Data;using System.Windows.Input;namespace RadGridViewTest{ public class MainPageViewModel { private readonly ObservableCollection<string> _innerCollection; public MainPageViewModel() { _innerCollection = new ObservableCollection<string> { "Taganrog", "Cherven Bryag" }; View = new PagedCollectionView(_innerCollection); ClearSorting = new DelegateCommand(onExecuteClearSorting); } public ICommand ClearSorting { get; private set; } public PagedCollectionView View { get; private set; } private void onExecuteClearSorting() { using (View.DeferRefresh()) // Comment this line to avoid exception { try { View.SortDescriptions.Clear(); } // This is the problem!!! catch (Exception ex) { MessageBox.Show(ex.Message); } } } } public class DelegateCommand : ICommand { private readonly Action _executeAction; public DelegateCommand(Action executeAction) { _executeAction = executeAction; } public bool CanExecute(object parameter) { return true; } public void Execute(object parameter) { _executeAction(); } public event EventHandler CanExecuteChanged; }}When i commented line with
using (View.DeferRefresh()) no exception occured.
Standart DataGrid also works well with DeferRefresh.