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

MVVM Binding ICommand to RadRichTextBox QuickAccessToolBar RadRibbonButton

3 Answers 155 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 07 Jun 2017, 03:34 PM

I'm trying to bind my own ICommand to a RadRibbonButton's Command. My code is based on the example at http://demos.telerik.com/silverlight/#RichTextBox/Binding. The relevant bit of the XAML hierarchy is:

<telerik:RadRichTextBoxRibbonUI DataContext="{Binding Path=Commands, ElementName=richTextBox}">
     <telerik:RadRichTextBoxRibbonUI.QuickAccessToolBar>
                        <telerik:QuickAccessToolBar>
                            <telerik:RadRibbonButton telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=SaveCommand}"     <== This is the button I want to bind my MVVM ICommand to.

Obviously, I removed the RichTextCommand attached property, and tried to bind the Command property to the ICommand on my viewmodel, which is set as the DataContext for the Window. As you can see, the example XAML (above) modifies DataContext at the RadRichTextBoxRibbonUI level, so to get back to "my" DataContext, I set a "Name" to an element higher up the visual tree, and used "ElementName" in my Binding, with the intent of using "Path=DataContext.MySaveCommand"; but I got a binding error saying that it couldn't even find the named element. I also tried {x:Reference} but got circular reference issues with that.

Please can someone demonstrate how to bind that command using MVVM?

My project references the "2016.3.1024.45" version of the assemblies. I tried attaching it; but it wouldn't let me.

3 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 07 Jun 2017, 03:43 PM
Just to be clear, I am building a WPF application, not Silverlight (which is what the example is for).
0
Accepted
Boby
Telerik team
answered on 09 Jun 2017, 10:53 AM
Hello Richard,

I'v just tried the approach from this StackOverflow thread, and it seems to work:
<telerik:RadRibbonButton Command="{Binding DataContext.MyCommand, RelativeSource={RelativeSource AncestorType=local:MainWindow}}"  />

where the data context of the MainWindow is a class which exposes ICommand MyCommand property. Can you confirm this is working on your side? If not, could you please send us small sample project, so that we can investigate the problem on our side?

Regards,
Boby
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Richard
Top achievements
Rank 1
answered on 09 Jun 2017, 02:38 PM
Thanks, yes, that works!
Tags
RichTextBox
Asked by
Richard
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Boby
Telerik team
Share this question
or