0

I'm setting up a RibbonComboBox bound to an ICollectionView in my ViewModel. When I select a new item, the ICollectionView's CurrentItem property does not change.

I have tried setting IsSynchronizedWithCurrentItem="True" on a RibbonGallery in the ComboBox, but this does not synchronize the CollectionView.

<RibbonGroup Header="MyGroup" DataContext="{StaticResource ResourceKey=MyViewModel}">
    <RibbonComboBox>
        <RibbonGallery IsSynchronizedWithCurrentItem="True" SelectedValue="{Binding MyCollectionView/}">
            <RibbonGalleryCategory ItemsSource="{Binding MyCollectionView}" DisplayMemberPath="Name"/>
        </RibbonGallery>
    </RibbonComboBox>
</RibbonGroup>

Everything works as I would expect, the ComboBox contains the full collection, I can select a new item from the list, however in my underlying code the CollectionView doesn't actually get it's CurrentItem property changed, even though the SelectedValue on the RibbonGallery is changed.

  • https://stackoverflow.com/questions/15555449/how-to-databind-selecteditem-of-ribboncombobox – Nebelkraehe Apr 29 '19 at 17:05
  • I appreciate the response, but that particular issue doesn't seem to be the same problem I am having. –  Apr 29 '19 at 17:52

1 Answers1

0

The only solution I could find was to duplicate the CollectionView's functionality in my View Model with a separate property that I could bind to, which is unfortunate given the standard combo box handles this just fine without all of that. It's also worth noting my early XAML had a mistake using SelectedValue instead of SelectedItem, however that alone did not cause the issue.

        public object SelectedItem
        {
            // This has to be done to cope with apparent bugs in the Ribbon controls.
            get => this.MyCollectionView.CurrentItem;
            set => this.MyCollectionView.MoveCurrentTo(value);
        }

The above will work in one direction from the UI, additional code will need to be added to handle the ICollectionView changing the CurrentItem programmatically and raise a PropertyChanged event.