I have a Silverlight DataGrid, a DataPager and a PagedCollectionView.
After the PagedCollection view is bound to the DataGrid, the first row of the DataGrid is selected.
This behaviour does not happen, if i am using an ObservableCollection. But due to the DataPager, I need to use the PagedCollectionView.
I am using Silverlight 5 RC, and the SL 4 Toolkit.
Example of Usage:
View:
<sdk:DataGrid x:Name="gridSomeItems" ItemsSource="{Binding SomeItems, Mode=TwoWay}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" CanUserSortColumns="True">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="Column1" Width="*" Binding="{Binding Column1}" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
<sdk:DataPager Source="{Binding Path=ItemsSource, ElementName=gridSomeItems}"/>
ViewModel:
public class SomeViewModel : ViewModelBase
{
public SomeViewModel(IDataAccess dataAccess)
{
_dataAccess = dataAccess;
_dataAccess.GetSomeItemsCompleted += GetSomeItemsCompleted;
_dataAccess.GetSomeItems();
}
public PagedCollectionView SomeItems { get; set; }
public SomeItem SelectedItem { get; set; }
private void GetSomeItemsCompleted(GetSomeItemsCompletedEventArgs e)
{
SomeItems = new PagedCollectionView(e.Result.SomeItems);
RaisePropertyChanged("SomeItems");
}
}
The best workaround is to set a
_isLoadingflag. The following code would be the correct code for the ViewModel:Please have a look at the row
SomeItems.MoveCurrentTo(null);– This command really sets the CurrentItem of the PagedCollectionView to null (not selected).It is still a workaround… Would be great if anybody came up with a better solution.