MVVM - how to override Binding to SaveCommand?

2 posts, 0 answers
  1. Rob Ainscough
    Rob Ainscough avatar
    188 posts
    Member since:
    Jan 2010

    Posted 05 Jun 2015 Link to this post

    I'm trying to figure out how to "intercept" the SaveCommand for RadRibbonBackstageItem and respond to the event in my MVVM code.


    <telerik:RadRichTextBoxRibbonUI IsMinimized="True"  Grid.Row="0" Grid.Column="0" BackstageClippingElement="{Binding ElementName=gridRadRtbParent}" DataContext="{Binding Commands, ElementName=ManageLettersRadRTB}" CollapseThresholdSize="50,50" Title="Letter" TitleBarVisibility="Collapsed" QuickAccessToolBarPosition="BelowRibbon" ApplicationButtonContent="File">
            <telerik:FontFamiliesProvider x:Key="FontFamiliesProvider" />
        <!-- Menu - File -->
            <telerik:RadRibbonBackstage >
                <telerik:RadRibbonBackstageItem Header="New" Icon="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/new.png" IsSelectable="false" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding NewDocumentCommand}" />
                <telerik:RadRibbonBackstageItem Header="Open" Icon="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/open.png" IsSelectable="false" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding OpenDocumentCommand}" />
                <telerik:RadRibbonBackstageItem x:Name="FileSave"  Header="Save" Icon="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/save.png" IsSelectable="false" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding SaveCommand}" >

    I tried to use SL5 interactivity but in order to make that work I had remove 

    "DataContext="{Binding Commands, ElementName=ManageLettersRadRTB}"

    from RadRichTextBoxRibbonUI which basically disables all the built in functionality ... not what I want.

     My goal is to respond with my own code when File - Save (which are RadRibbonBackstageItem) is selected from the RadRichTextBoxRibbonUI and not use the default controls Save process.

    Is this possible?  If so, could you provide any hints/sample.

    Cheers, Rob.


  2. Petya
    Petya avatar
    983 posts

    Posted 08 Jun 2015 Link to this post

    Hi Rob,

    The easiest way to intercept the save command is by subscribing to the CommandExecuting/CommandExecuted events of RadRichTextBox, but this is not a very MVVM-friendly solution.

    The other alternative is to create custom command(s) and set the data context of the backstage (or specific backstage item) to your view model. I'm sending you a simple example with sample implementation for the save command. It also shows how to create a DependencyProperty of type RadRichTextBox and pass it to the custom command.

    In the sample I've set the data context of the backstage item to my view model, which may be a bit inconvenient if you plan on creating many custom commands, but is the only solution I could give.
    <telerik:RadRibbonBackstageItem Header="Open" Icon="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/open.png" IsSelectable="false" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding OpenDocumentCommand}"/>
    <telerik:RadRibbonBackstageItem Header="Save" Icon="/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/save.png" IsSelectable="false" DataContext="{Binding ElementName=Commands}" Command="{Binding MySaveCommand}"/>

    I hope this helps.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top