RibbonView - Paint with MVVM example

4 posts, 0 answers
  1. Trevor
    Trevor avatar
    5 posts
    Member since:
    Jul 2011

    Posted 27 Jul 2011 Link to this post

    I would really appreciate your help to point me in the right direction.

    I've been working through the example provided in order to build a dynamically generated menu but cant seem to find the code responsible for the following (where am I missing the ButtonsTemplateSelector in the code?):
    <mvvm:ButtonsTemplateSelector x:Key="groupsSelector" Button="{StaticResource ButtonTemplate}"
                        SplitButton="{StaticResource SplitButtonTemplate}" ButtonsGroup="{StaticResource ButtonsGroup}"
                        SmallButtonGroup="{StaticResource SmallButtonGroup}" />
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 01 Aug 2011 Link to this post

    Hi Trevor,

    I'm attaching the code for all RibbonView examples. In addition, here is the code for the ButtonsTemplateSelector.

    using System.Windows;
    using Telerik.Windows.Examples.RibbonView.MVVM.ViewModels;
    using System.Windows.Controls;
    using Telerik.Windows.Controls;
     
    namespace Telerik.Windows.Examples.RibbonView.MVVM
    {
        public class ButtonsTemplateSelector : DataTemplateSelector
        {
            public DataTemplate Button { get; set; }
            public DataTemplate SplitButton { get; set; }
            public DataTemplate ButtonsGroup { get; set; }
            public DataTemplate SmallButtonGroup { get; set; }
     
            public override DataTemplate SelectTemplate(object item, DependencyObject container)
            {
                if (item is SplitButtonViewModel)
                {
                    return SplitButton;
                }
                else if (item is ButtonGroupViewModel)
                {
                    return ((ButtonGroupViewModel)item).IsSmallGroup ? SmallButtonGroup : ButtonsGroup;
                }
                else
                {
                    return Button;
                }
            }
        }
    }

    Let me know if you need further assistance.

    Regards,
    Kiril Stanoev
    the Telerik team

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

  3. DevCraft banner
  4. Trevor
    Trevor avatar
    5 posts
    Member since:
    Jul 2011

    Posted 01 Aug 2011 Link to this post

    Hi Kiril Stanoev,

    Thank you very much, that's exactly what I was looking for.

    I wonder if you can help me with one last problem I've encountered using the example of the RibbonView. I am trying to bind click events to the various buttons, but since the buttons are of type ButtonViewModel split = new ButtonViewModel(); and not of RadButton i cant access the Click event. What would be the best way to adjust the current example to allow this functionality?
  5. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 01 Aug 2011 Link to this post

    Hi Trevor,

    In my opinion, if you want to stay truly MVVM, you need to use commands for the buttons. Please take a look at the attached project in this forum post as it shows one basic implementation of a RadButton command (RadRibbonButton inherits RadButton, so commands are supported).

    Greetings,
    Kiril Stanoev
    the Telerik team

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

Back to Top