Binding RadRibbonButton to ICommand

6 posts, 0 answers
  1. Greg
    Greg avatar
    13 posts
    Member since:
    Jun 2011

    Posted 07 Nov 2011 Link to this post

    Looking at the documentation for the RibbonView and RibbonButton, I see:

    In order to create a command you have to create a static read-only instance ofTelerik.Windows.Controls.RoutedUICommand and then add execute and you can execute event handlers to theTelerik.Windows.Controls.CommandManager class.

    Is this seriously the only binding implementation that the RibbonButton supports?! Can't we simply bind the button to an ICommand? Forcing the ugly, complicated implementation of a static read-only RoutedUICommand can't be the only way.

    -Greg
  2. Greg
    Greg avatar
    13 posts
    Member since:
    Jun 2011

    Posted 07 Nov 2011 Link to this post

    Okay, digging in the Silverlight documentation I see that the RadRibbonButton seemingly does support ICommand, but for some reason I'm getting BindingExpression path errors in my project.

    -Greg
  3. UI for WPF is Visual Studio 2017 Ready
  4. Greg
    Greg avatar
    13 posts
    Member since:
    Jun 2011

    Posted 07 Nov 2011 Link to this post

    Okay, so I'm using PRISM and I've placed the RadRibbonView in my Shell.xaml as such:

    <telerik:RadRibbonView prism:RegionManager.RegionName="Region.Ribbon"
                                       Grid.Row="0"
                                       Title="Graphite" />

    I have a RadRibbonTab View that looks like this:

    <telerik:RadRibbonTab x:Class="Company.Graphite.Modules.PartData.Views.AdminRibbonTabView"
                          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                          xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.RibbonView"
                          mc:Ignorable="d"
                          Header="Admin">
        <telerik:RadRibbonGroup Header="Actions">
            <telerik:RadRibbonButton LargeImage="pack://application:,,,/Company.Graphite.Resources;component/Icons/32x32/Grey/Standby.png"
                                     Text="Close"
                                     Size="Large"
                                     Command="{Binding Screen.CloseCommand}" />
        </telerik:RadRibbonGroup>
    </telerik:RadRibbonTab>

    My View's code-behind sets the DataContext to my ViewModel. However, when I run the app I see this in the Output window:

    System.Windows.Data Error: 40 : BindingExpression path error: 'Screen' property not found on 'object' ''ShellViewModel' (HashCode=9898044)'. BindingExpression:Path=Screen.CloseCommand; DataItem='ShellViewModel' (HashCode=9898044); target element is 'RadRibbonButton' (Name=''); target property is 'Command' (type 'ICommand')

    That error makes total sense because the ShellViewModel doesn't expose a Screen property. Why not? Because that's not the ViewModel that belongs with that View! Somehow the DataContext for the View that defines my RadRibbonTab is getting set to ShellViewModel despite the fact that I set it to something completely different in the View's code behind.

    What gives? Is the region adapter for the RadRibbonView stomping on my assigned DataContext perhaps?

    Bear in mind that all the rest of the application is working normally. In fact, my ViewModels and Views have only been touched in order to switch from a working implementation of Microsoft's ribbon to Telerik's ribbon. If I change nothing except the XAML and switch back to the Microsoft ribbon then everything works again.

    Any ideas?
  5. Greg
    Greg avatar
    13 posts
    Member since:
    Jun 2011

    Posted 07 Nov 2011 Link to this post

    I'm at a loss. I created a custom PRISM region adapter and threw in a breakpoint. Everything I can control seems to be working. For example, in the first attached screenshot (radribbonview-01.png) you can see the DataContext for the RadRibbonTab is set as I would expect (CustomersViewModel). However, when the app is running and I have a look with Snoop (radribbonview-02.png) you can see that that DataContext is set to my ShellViewModel via inheritance.

    Any ideas? Anybody?
  6. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 08 Nov 2011 Link to this post

    Hi Greg,

    In the RadRibbonView control there was an issue with the data context propagation, but it was fixed in the Q2 2011 SP1 (version 2011.2.0920) release. This is why I wanted to ask you about the version of the RadControls for WPF that you're using. Can you try your solution with the 2011.2.920 version?

    I also attached a sample application where the RadRibbonView is used as a region in a PRISM scenario. If the Q2 2011SP1 release doesn't fix your issues, can you please modify the solution to better illustrate your scenario and we will look into the issue further? Thank you in advance for your cooperation.

    Regards,
    Tina Stancheva
    the Telerik team

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

  7. Greg
    Greg avatar
    22 posts
    Member since:
    Aug 2011

    Posted 08 Nov 2011 Link to this post

    Updating to the Q2 2011 SP1 (version 2011.2.0920) release fixed the issue. Thanks!

    -Greg
Back to Top
UI for WPF is Visual Studio 2017 Ready