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

Contextual Tabs via MVVM

7 Answers 197 Views
RibbonView and RibbonWindow
This is a migrated thread and some comments may be shown as answers.
sean
Top achievements
Rank 1
sean asked on 07 Aug 2011, 10:23 AM
Hello

I've been looking at upgrading from RadRibbonBar to RadRibbonView. Previously, to bind the contextual tabs in an mvvm way I used the ContextualGroupContainer property and bound it to an ObservableCollection<RadContextualGroup>, felt slightly non-mvvm as the view model for the ribbon had a collection of view elements.

I was hoping with the RadRibbonView there would be a nicer way but the contextualgroups property on the control is readonly?  Is there a way of binding the contextual tabs this time around?

Alternatively, I could do it with an attached property or code behind - but I'd prefer not to.

Another side question, is binding the tabs and using the keytip service possible? If you use a HierarchicalDataTemplate I don't see a way of setting the AccessText property?

Thanks.

7 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 10 Aug 2011, 02:19 PM
Hello Sean,

I attached a sample project demonstrating how to take advantage of the RadRibbonView in a databinding scenario that can help you get started on your task.

Unfortunately in the RadRibbonView control for Silverlight you cannot bind the KeyTipService.AccessText property and we logged this item as a bug in our PITS where you can track its progress. We will do our best to fix this issue as soon as possible and I updated your Telerik points for bringing it to our attention.

Kind regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Jonathan
Top achievements
Rank 1
answered on 20 Oct 2011, 11:10 AM
Hi,

I'm trying to do this to. The example you gave does not bind the ContextualGroups (they are hard-coded in the xaml). Is there a way to bind to the model? ContextualGroups doesn't have an ItemsSource.

Thanks,
Jon
0
sean
Top achievements
Rank 1
answered on 20 Oct 2011, 11:24 AM
Hi Jonathan,

After looking at the code i came to the conclusion its still not possible in a true MVVM way.

However, i used something similar to my first workaround. Using an AP, i can do this:

<t:RadRibbonView myAPs:RibbonExtensions.ContextualGroupsBinding="{Binding ContextualGroups}">

The ContextualGroups collection is a business object, not telerik's ribbon groups. I can supply the code for the AP if desired.
0
Jonathan
Top achievements
Rank 1
answered on 20 Oct 2011, 01:06 PM
Thanks Sean, would be great if you can post the code :)
0
sean
Top achievements
Rank 1
answered on 20 Oct 2011, 01:52 PM
This relies on a class RibbonContextualGroup, which represents the business object of the group:

public static readonly DependencyProperty ContextualGroupsBindingProperty =
           DependencyProperty.RegisterAttached(
               "ContextualGroupsBinding",
               typeof(INotifyCollectionChanged),
               typeof(RadRibbonView),
               new System.Windows.PropertyMetadata(null, new PropertyChangedCallback(OnContextualGroupsBindingChanged))
               );
 
        public static void SetContextualGroupsBinding(RadRibbonView element, INotifyCollectionChanged value)
        {
            element.SetValue(ContextualGroupsBindingProperty, value);
        }
 
        public static INotifyCollectionChanged GetContextualGroupsBinding(RadRibbonView element)
        {
            return (INotifyCollectionChanged)element.GetValue(ContextualGroupsBindingProperty);
        }
 
        private static void OnContextualGroupsBindingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue is INotifyCollectionChanged)
            {
                RadRibbonView ribbon = sender as RadRibbonView;
 
                INotifyCollectionChanged collection = (INotifyCollectionChanged)e.NewValue;
 
                collection.CollectionChanged += (object o, NotifyCollectionChangedEventArgs args) =>
                {
                    switch (args.Action)
                    {
                        case NotifyCollectionChangedAction.Add:
 
                             
                            RadRibbonContextualGroup newGroup = null;
 
                            foreach (RibbonContextualGroup group in args.NewItems)
                            {
                                newGroup = new RadRibbonContextualGroup(); // or load from template
 
                                if (newGroup != null)
                                {
                                    newGroup.Name = group.Name;
                                    newGroup.DataContext = group;
                                    ribbon.ContextualGroups.Add(newGroup);
                                }
                            }
 
                            break;
                        case NotifyCollectionChangedAction.Remove:
                            throw new Exception("Remove action is unsupported");
 
                        case NotifyCollectionChangedAction.Replace:
                            throw new Exception("Replace action is unsupported");
 
                        case NotifyCollectionChangedAction.Reset:
                            ribbon.ContextualGroups.Clear();
                            break;
                    }
                };
            }
        }

0
kilhoffer
Top achievements
Rank 1
answered on 31 Oct 2013, 04:24 PM
Why would you guys post a zipped up solution that doesn't at all bind contextual groups as you've stated? They're hardcoded in XAML. Does Telerik have a real solution for this much needed feature??
0
Tina Stancheva
Telerik team
answered on 05 Nov 2013, 02:37 PM
Hello Anthony,

Unfortunately the RibbonView ContextualGroups cannot be data-bound at the moment. We have logged this task in our to-do list but at the moment I can't bind to any time frame for an implementation.

Regards,
Tina Stancheva
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
RibbonView and RibbonWindow
Asked by
sean
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Jonathan
Top achievements
Rank 1
sean
Top achievements
Rank 1
kilhoffer
Top achievements
Rank 1
Share this question
or