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

Handling events from dynamically created RibbonView buttons

2 Answers 71 Views
RibbonView and RibbonWindow
This is a migrated thread and some comments may be shown as answers.
Rolf
Top achievements
Rank 1
Rolf asked on 02 Mar 2014, 08:59 PM
Hi,

I have a project which will use the RibbonView (if I can make it work like I want). I have managed to bind simple business objects to the ribbon and display tabs, groups and buttons including icons, but this is where it stops. My problem is that I am unable to find a good way to attach events to the buttons dynamically. The application has a lot of child views and each of these will have it's own items on the ribbonview. I was hoping that I could have one ribbon view defined in the main view and just bind business objects from the childviews. I was also hoping I could mix items on the ribbon view from both the main view and the active child view so that I don't have to add those "global" items everytime.

What I have done now is that I have one event handler in the datatemplate which handles all events from all buttons on the ribbon. This is a problem as I cannot distinguish them in any way except from looking at the content/text of the buttons, but this seems rather "ugly".

Do you have any good suggestion on how I can dynamically add items to ribbonview for a childview with attached events? Can I achieve this just by binding business objects or do I have to create a viewmodel and a view with a whole RadRibbonView for each separate childview? So far I haven't defined anything in xaml except for the ribbon view itself and the templates. Will this work or must I start defining tabs, groups and buttons so that I can add dedicated events to each of them?

I have looked at the RadRibbonView demo (Paint) you have where business objects are bound to the RibbonView with tabs, groups and buttons including icons, but no events are attached so it doesn't help me anything.

I'm sure there is some easy solution to this as it has to be a common scenario to dynamically populate a ribbon from multiple views. Probably I'm just missing something obvious, but hopefully you can help me with this.
 
Regards,
Rolf




2 Answers, 1 is accepted

Sort by
0
Rolf
Top achievements
Rank 1
answered on 03 Mar 2014, 10:19 AM
I just want to add that you can replace Event with Command in the post above. And the Paint example I'm referring to is called "Paint with MVVM" and can be found in your WPF demo application.

Also, the exact same problem I have is mentioned in the 2nd last reply in this post:
http://www.telerik.com/forums/ribbonview---paint-with-mvvm-example#5OSJcUTQrUu9xlKFm6elvw

The last answer from Kiril Stanoev does not help though. His example has the commands hard coded in xaml on the buttons which is not dynamic and exactly what we don't want to do. Or is there something I don't understand here? Is it possible to implement the commands in the view models that are bound to the ribbon view so that they automatically become attached to the buttons that wrap the view models?
0
Martin Ivanov
Telerik team
answered on 05 Mar 2014, 08:22 PM
Hello Rolf,

I am not sure if I understand your scenario well. That's why I will highly appreciate it if you can provide us with a sample project with your implementation. This will allow us to understand your scenario better and assist you further.

Can you also elaborate on why you don't want to define the commands in XAML. I would generally recommend that you bind the RadRibbonButtons Command property to a business command. You should do that in the DataTemplates that define RadRibbonButtons. This would however mean that you need to make sure that the business commands in all your child models have the same name. Another approach you can use is to define an ItemTemplateSelector to choose a different DataTemplates with different RibbonButton definitions for the different object types. This would allow you to bind the buttons created to wrap the view models to different commands.

Regards,
Martin
Telerik

DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

Tags
RibbonView and RibbonWindow
Asked by
Rolf
Top achievements
Rank 1
Answers by
Rolf
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or