This is a migrated thread and some comments may be shown as answers.

Navigator update after Remove

3 Answers 22 Views
CollectionNavigator
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 02 Mar 2016, 09:38 PM
I've got a RadCollectionNavigator with Source bound to an ObservableCollection<int> in the VM and CurrentItem two-way bound to an int in the VM. When I call ObservableCollection<int>.Remove I'm expecting the RadCollectionNavigator to update and change CurrentItem, but this isn't happening. Is this something it can do or do I have to implement an update to the CurrentItem binding myself in the VM?

3 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 03 Mar 2016, 11:16 AM
Hello Kevin,

I have tested this scenario on my end and it works as expected. Please check the attached sample project for a reference and let me know how it works for you.

Regards,
Yoan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Kevin
Top achievements
Rank 1
answered on 07 Mar 2016, 05:40 PM

Thanks, Yoan. But I think in your example, it's actually the ListBox that's updating SelectedItem after the Remove. If you comment out the ListBox element in the XAML:

<!--<ListBox 
            SelectedItem="{Binding ElementName=collectionNavigator, Path=CurrentItem, Mode=TwoWay}"                  
            ItemsSource="{Binding ElementName=collectionNavigator, Path=CollectionView}" />-->

you get the behavior I'm experiencing. Run the app, press <end> in the Navigator, then press <begin> in the Navigator. You should now be seeing Liverpool at the bottom of the window. Now click "Remove item". Nothing will change. But if you now click <end> then <begin> in the Navigator, you'll see "Manchester Utd." at the bottom of the window. So it doesn't seem like RadCollectionNavigator will update CurrentItem when an item is removed from the ObservableCollection.

0
Yoan
Telerik team
answered on 10 Mar 2016, 09:23 AM
Hello,

Indeed, you are right, I have missed the part for updating the source collection from the ViewModel. However, you can easily overcome this by updating the Source of the CollectionNavigator manually:
ObservableCollection<Club> sourceCollection;
        public MainWindow()
        {
            InitializeComponent();
 
            this.DataContext = new MyViewModel();
            sourceCollection = (this.DataContext as MyViewModel).Clubs;
            sourceCollection.CollectionChanged += Clubs_CollectionChanged;
 
            this.collectionNavigator.Source = sourceCollection;
 
        }
 
        void Clubs_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            this.collectionNavigator.Source = null;
            this.collectionNavigator.Source = sourceCollection;
        }
 
        private void Button1_Click(object sender, RoutedEventArgs e)
        {
        }
 
        private void Button2_Click(object sender, RoutedEventArgs e)
        {
            sourceCollection.RemoveAt(0);
        }

I hope this helps.

Regards,
Yoan
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
CollectionNavigator
Asked by
Kevin
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Kevin
Top achievements
Rank 1
Share this question
or