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

RibbonView - Paint with MVVM example

3 Answers 165 Views
RibbonView and RibbonWindow
This is a migrated thread and some comments may be shown as answers.
Trevor
Top achievements
Rank 1
Trevor asked on 27 Jul 2011, 03:03 PM
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}" />

3 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 01 Aug 2011, 11:21 AM
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 >>

0
Trevor
Top achievements
Rank 1
answered on 01 Aug 2011, 12:07 PM
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?
0
Kiril Stanoev
Telerik team
answered on 01 Aug 2011, 12:36 PM
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 >>

Tags
RibbonView and RibbonWindow
Asked by
Trevor
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Trevor
Top achievements
Rank 1
Share this question
or