Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7603245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:36:51+00:00 2026-05-30T23:36:51+00:00

I am using Caliburn micro(1.3)/MVVM and Silverlight. When I update the itemsource RadGridView, I

  • 0

I am using Caliburn micro(1.3)/MVVM and Silverlight. When I update the itemsource RadGridView, I lose the selected items. I found a blog about implementing a behavior to save the selected items when you are implementing MVVM. I can get the selected items, but I cannot set them back once the itemsource is refreshed. Can someoneshow me how to implement this using caliburn.micro and the RadGridVIew? I think the best way to go is to create a caliburn micro convention, but I can only find a reference for creating a convention for selectedItem, not selectedItems.

Can someone show me how to accomplish this? I tried the following, but it does not work.

  private static void SetRadGridSelecteditemsConventions()
    {
        ConventionManager
            .AddElementConvention<DataControl>(DataControl.ItemsSourceProperty, "SelectedItem", "SelectionChanged")
            .ApplyBinding = (viewModelType, path, property, element, convention) =>
                                {
                                    ConventionManager.SetBinding(viewModelType, path, property, element, convention, DataControl.ItemsSourceProperty);

                                    if (ConventionManager.HasBinding(element, DataControl.SelectedItemProperty))
                                        return true;

                                    var index = path.LastIndexOf('.');
                                    index = index == -1 ? 0 : index + 1;
                                    var baseName = path.Substring(index);
                                    foreach (var selectionPath in
                                        from potentialName in ConventionManager.DerivePotentialSelectionNames(baseName)
                                        where viewModelType.GetProperty(potentialName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance) != null
                                        select path.Replace(baseName, potentialName))
                                    {
                                        var binding = new Binding(selectionPath) { Mode = BindingMode.TwoWay };
                                        BindingOperations.SetBinding(element, DataControl.SelectedItemProperty, binding);
                                    }
                                    return true;
                                };
    }

Thanks,
Stephane

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:36:53+00:00Added an answer on May 30, 2026 at 11:36 pm

    You should use a behavior for this since the SelectedItems property is readonly.
    Telerik has an example for this, only the example is not specific for caliburn.micro.
    If you add the following class to your project:

    public class MultiSelectBehavior : Behavior<RadGridView>
    {
        public INotifyCollectionChanged SelectedItems
        {
            get { return (INotifyCollectionChanged)GetValue(SelectedItemsProperty); }
            set { SetValue(SelectedItemsProperty, value); }
        }
    
        public static readonly DependencyProperty SelectedItemsProperty =
            DependencyProperty.Register("SelectedItems", typeof(INotifyCollectionChanged), typeof(MultiSelectBehavior), new PropertyMetadata(OnSelectedItemsPropertyChanged));
    
    
        private static void OnSelectedItemsPropertyChanged(DependencyObject target, DependencyPropertyChangedEventArgs args)
        {
            var collection = args.NewValue as INotifyCollectionChanged;
            if (collection != null)
            {
                collection.CollectionChanged += ((MultiSelectBehavior)target).ContextSelectedItems_CollectionChanged;
            }
        }
    
        protected override void OnAttached()
        {
            base.OnAttached();
    
            AssociatedObject.SelectedItems.CollectionChanged += GridSelectedItems_CollectionChanged;
        }
    
        void ContextSelectedItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            UnsubscribeFromEvents();
    
            Transfer(SelectedItems as IList, AssociatedObject.SelectedItems);
    
            SubscribeToEvents();
        }
    
        void GridSelectedItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            UnsubscribeFromEvents();
    
            Transfer(AssociatedObject.SelectedItems, SelectedItems as IList);
    
            SubscribeToEvents();
        }
    
        private void SubscribeToEvents()
        {
            AssociatedObject.SelectedItems.CollectionChanged += GridSelectedItems_CollectionChanged;
    
            if (SelectedItems != null)
            {
                SelectedItems.CollectionChanged += ContextSelectedItems_CollectionChanged;
            }
        }
    
        private void UnsubscribeFromEvents()
        {
            AssociatedObject.SelectedItems.CollectionChanged -= GridSelectedItems_CollectionChanged;
    
            if (SelectedItems != null)
            {
                SelectedItems.CollectionChanged -= ContextSelectedItems_CollectionChanged;
            }
        }
    
        public static void Transfer(IList source, IList target)
        {
            if (source == null || target == null)
                return;
    
            target.Clear();
    
            foreach (var o in source)
            {
                target.Add(o);
            }
        }
    }
    

    This behavior takes care of the synchronization between collection RadGridView.SelectedItems and MultiSelectBehavior.SelectedItems.

    Now we need to have an ObservableCollection in the ViewModel

        //Collection holding the selected items
        private ObservableCollection<object> selectedGridItems;
        public ObservableCollection<object> SelectedGridItems
        {
            get
            {
                if (selectedGridItems == null)
                    selectedGridItems = new ObservableCollection<object>();
    
                return selectedGridItems;
            }
            set
            {
                if (selectedGridItems == value) return;
                selectedGridItems = value;
                NotifyOfPropertyChange(() => SelectedGridItems);
            }
        }
    
        //Deselect all selected items in the gridview
        public void ClearSelectedGridItems()
        {
            SelectedGridItems.Clear();
        }
    

    Last thing is bind the behavior in the view

        <telerik:RadGridView x:Name="CustomLogs" AutoGenerateColumns="true" SelectionMode="Extended">
            <i:Interaction.Behaviors>
                <local:MultiSelectBehavior SelectedItems="{Binding SelectedGridItems}"/>                
            </i:Interaction.Behaviors>                
        </telerik:RadGridView>
    

    Thats it, hope it helps you!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning about using Caliburn.Micro as a MVVM framework for a WPF application. In
I'm using MVVM via Caliburn Micro on WP7. I have a popup that is
Using Caliburn and Silverlight, I found that if I do: <Button PresentationFramework:Message.Attach=ContainerCommand InstructorProfileCommand() Height=60
I'm using Caliburn Micro MVVM. I want to make category selection usercontrol consisting of
We're using Caliburn.Micro/Silverlight 4 and life is good. I'm trying to bind a combobox's
Using the IWindowManager of Caliburn.Micro , is it possible to create a borderless window
I'm using Caliburn and the MVVM pattern in a WPF application, and am trying
I'm using Caliburn Micro for my project, and I decided to use Fluent Ribbon
I am using the Caliburn Micro Window Manager to display a dialog. I would
I am currently trying to learn how to implement MVVM using Unity and Caliburn

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.