Contextual Tabs via MVVM

8 posts, 0 answers
  1. sean
    sean avatar
    6 posts
    Member since:
    Oct 2012

    Posted 07 Aug 2011 Link to this post

    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.
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 10 Aug 2011 Link to this post

    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 >>

  3. DevCraft banner
  4. Jonathan
    Jonathan avatar
    22 posts
    Member since:
    Apr 2011

    Posted 20 Oct 2011 Link to this post

    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
  5. sean
    sean avatar
    6 posts
    Member since:
    Oct 2012

    Posted 20 Oct 2011 Link to this post

    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.
  6. Jonathan
    Jonathan avatar
    22 posts
    Member since:
    Apr 2011

    Posted 20 Oct 2011 Link to this post

    Thanks Sean, would be great if you can post the code :)
  7. sean
    sean avatar
    6 posts
    Member since:
    Oct 2012

    Posted 20 Oct 2011 Link to this post

    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;
                        }
                    };
                }
            }

  8. kilhoffer
    kilhoffer avatar
    40 posts
    Member since:
    May 2007

    Posted 31 Oct 2013 Link to this post

    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??
  9. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 05 Nov 2013 Link to this post

    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 >>
Back to Top
DevCraft banner