Cannot bind Commands to RadRibbonButton

12 posts, 0 answers
  1. Tim
    Tim avatar
    85 posts
    Member since:
    Aug 2008

    Posted 17 Apr 2010 Link to this post

    Is there any reason why I should be getting this error for a very simple MVVM scenario binding a Command either through Xaml or Code Behind?  I am using the 2010 Q1 controls and this is a RadRibbonButton.  It's binding to a DelegateCommand<bool> in this case.  I get an "object reference not set" error when the RibbonBar shows up even though the Command in the VM has already been instantiated and the ViewModel is already bound to the DataContext of the UserControl.  This makes no sense since I use the same pattern for every commanding scenario and this is the first time I've tried it with Rad controls.

       at Microsoft.Practices.Composite.Presentation.Commands.DelegateCommand`1.System.Windows.Input.ICommand.CanExecute(Object parameter)
       at Telerik.Windows.Controls.RadButton.CanExecuteApply()
       at Telerik.Windows.Controls.RadButton.ChangeCommand(ICommand oldCommand, ICommand newCommand)
       at Telerik.Windows.Controls.RadButton.OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
       at Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(DependencyObject d, DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
       at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
       at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
       at System.Windows.Data.BindingExpression.SendDataToTarget()
       at System.Windows.Data.BindingExpression.SourceAcquired()
       at System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(Object sender, DataContextChangedEventArgs e)
       at System.Windows.Data.BindingExpression.DataContextChanged(Object sender, DataContextChangedEventArgs e)
       at System.Windows.DataContextChangedEventHandler.Invoke(Object sender, DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnTreeParentUpdated(DependencyObject newParent, Boolean bIsNewParentAlive)
       at System.Windows.DependencyObject.UpdateTreeParent(IManagedPeer oldParent, IManagedPeer newParent, Boolean bIsNewParentAlive, Boolean keepReferenceToParent)
       at MS.Internal.FrameworkCallbacks.ManagedPeerTreeUpdate(IntPtr oldParentElement, IntPtr parentElement, IntPtr childElement, Byte bIsParentAlive, Byte bKeepReferenceToParent)
  2. Jim Daly
    Jim Daly avatar
    13 posts
    Member since:
    Apr 2010

    Posted 19 Apr 2010 Link to this post

    Could you post the code for RadRibbonButton that you are binding?

    It looks like your command is expecting a bool value. Are you passing this as a CommandParameter?
  3. DevCraft banner
  4. Tim
    Tim avatar
    85 posts
    Member since:
    Aug 2008

    Posted 19 Apr 2010 Link to this post

    Essentlially I am trying to have a menu option for "Full Screen Mode".  So let's start simple and just add a Quick Access toolbar button.  The "Command" is bound to the "OnFullScreenModeChanged" CommandDelegate<bool> object.  The "CommandParameter" is bound to the "IsFullScreen" property but uses it's inverse value by using a "NotOperatorValueConverter".  The "Tooltip" of the TooltipService is simply bound to the "FullScreenHint" property.

    This portion of the application is using a "ViewModel-First" approach so the ViewModel gets passed into the constructor of the View (which is hosting the RibbonBar obviously).  However, I immediately get an "Object reference not set" error (even after I've stepped through everything and verified that there are no "null" references in the ViewModel).  The weird thing is that the button works!  I just want it to NOT throw the error!

    View Model:
    /// <summary> 
    /// Returns whether the Application is Full Screen or not 
    /// </summary> 
    public bool IsFullScreen  
        get {  
            return System.Windows.Application.Current.Host.Content.IsFullScreen;  
        } 
     
    /// <summary> 
    /// Returns the text hint for full screen UIHints 
    /// </summary> 
    public string FullScreenHint 
        get { 
            return System.Windows.Application.Current.Host.Content.IsFullScreen ?  
                "Exit Full Screen Mode" :  
                "Enter Full Screen Mode"
        } 
     
    /// <summary /> 
    public DelegateCommand<bool> OnFullScreenModeChanged { getprivate set; } 
     
    public ViewModel(IUnityContainer container) 
        this.container = container; 
     
        this.OnFullScreenModeChanged = new DelegateCommand<bool>(this.ChangeFullScreenMode); 

    Xaml:
    <telerikRibbonBar:RadRibbonBar x:Name="ribbonBar"
        <!-- Quick Access Toolbar --> 
        <telerikRibbonBar:RadRibbonBar.QuickAccessToolBar> 
            <telerikRibbonBar:QuickAccessToolBar> 
                <telerikRibbonBar:RadRibbonButton 
                    x:Name="qbtnFullScreen" 
                    Size="Small" 
                    Command="{Binding OnFullScreenModeChanged}" 
                    CommandParameter="{Binding IsFullScreen, Converter=NotOperatorValueConverter}" 
                    ToolTipService.ToolTip="{Binding FullScreenHint}" 
            /> 
            </telerikRibbonBar:QuickAccessToolBar> 
        </telerikRibbonBar:RadRibbonBar.QuickAccessToolBar> 
    </telerikRibbonBar:RadRibbonBar> 

  5. Ivan
    Admin
    Ivan avatar
    519 posts

    Posted 22 Apr 2010 Link to this post

    Hello Tim,

    Thank you for the sample code.

    As the sample code looks good could send us the problematic project to investigate the issue. Meantime we will prepare a simple project with ribbon bar and delegate commands. We will attach it here soon.

    Please keep an eye on this thread.

    Sincerely yours,
    Ivan
    the Telerik team

    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 Public Issue Tracking system and vote to affect the priority of the items.
  6. Uri
    Uri avatar
    1 posts
    Member since:
    Feb 2011

    Posted 23 Feb 2011 Link to this post

    I don't know if it is still relevant, but I think your problem is that the parameter sent to the CanExecute method is null (which cannot be cast to bool).
    This method is called as soon as the Command parameter is set, but before the CommandParameter is set.
    To fix the problem you should change the replace the order of the parameters in the XAML, like this:

    <telerikRibbonBar:RadRibbonBar.QuickAccessToolBar> 
            <telerikRibbonBar:QuickAccessToolBar> 
                <telerikRibbonBar:RadRibbonButton 
                    x:Name="qbtnFullScreen" 
                    Size="Small" 
    CommandParameter="{Binding IsFullScreen, Converter=NotOperatorValueConverter}"
                    Command="{Binding OnFullScreenModeChanged}" 
                    ToolTipService.ToolTip="{Binding FullScreenHint}" 
            /> 
            </telerikRibbonBar:QuickAccessToolBar> 
        </telerikRibbonBar:RadRibbonBar.QuickAccessToolBar> 


    This will ensure the a parameter value is set before the CanExecute is called.
  7. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 28 Feb 2011 Link to this post

    Hello Uri,

    Thank you for your input to this thread. I am sure that the community appreciates it. I hope that the attached RibbonBar sample application will also be helpful.

    Best wishes,
    Tina Stancheva
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  8. Peter
    Peter avatar
    28 posts
    Member since:
    Oct 2006

    Posted 08 May 2011 Link to this post

    Hello Tina,

    The application sample is very useful. I tried to implement this in my project, but I wondered how/where you bind the ContextualTabs? If this is just not a part of the demo app, I want to know how this could be achieved anyhow.

    Perhaps extending the demo would be interesting for more people out there.

    Best regards,
    Hans-Peter Schmidt
  9. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 11 May 2011 Link to this post

    Hello Hans-Peter Schmidt,

    I attached a sample project illustrating how to databind the ContextualTabs. However, please keep in mind that the current implementation of the RibbonBar has many known limitations in databinding scenarios. This is why we are currently working on a new implementation of the control - RibbonView. The RibbonView has the same API as the RibbonBar, but it will significantly improve the databinding and design-time support of the ribbon control as well as its performance. You will be able to give the new ribbon implementation a try in the upcoming Beta release so stay tuned for that.

    Kind regards,
    Tina Stancheva
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  10. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 04 Oct 2011 Link to this post

    I was trying to bind a RadRibbonCombobox to a RadRibbonButton CommandParameter which did not work just because I shold be using the RibbonView and NOT the RibbonBar which is buggy!

    My code which is working in the RibbonView but not in the RibbonBar is:
    <telerik:RadRibbonComboBox EmptyText="Format d'export" SelectedIndex="0" Name="cbxFormat" >
                                        <telerik:RadRibbonComboBoxItem Content="Fichier Excel" />
                                        <telerik:RadRibbonComboBoxItem Content="Fichier Csv" />
                                    </telerik:RadRibbonComboBox>
                                    <telerikRibbonView:RadRibbonButton Text="Exporter commande" SmallImage="/SoPratic.SL;component/Images/Export.png" SplitText="True" Name="btnExport"
                                                                      CommandParameter="{Binding ElementName=cbxFormat, Path=SelectedValue}"
                                                                      Command="{Binding ElementName=commandes, Path=ExportCommand}" />

    It took my five hours to figure this out :(

    John.
  11. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 07 Oct 2011 Link to this post

    Hi John,

    Indeed the RadRibbonBar control has many known limitations especially in databinding scenarios. This is why the RadRibbonView control was released - a new implementation of the ribbon UI but keeping pretty much the same API.

    I am really sorry to hear that you have spent such a long time trying to use the RadRibbonBar. We are currently trying to popularize the RadRibbonView control as a replacement of the RadRibbonBar control. And we will definitely take your feedback into consideration and  discuss how we can prevent our users from hitting the same walls as you did and further spread the news of the new control and its features.

    So thanks again for your feedback.

    Best wishes,
    Tina Stancheva
    the Telerik team

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

  12. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 08 Oct 2011 Link to this post

    Hello Tina,
    I have read here and there that they are "known limitations" but I was unable to find which they where...

    So I see only two simple things to do:
    - List the known limitations in a chapter "Known limitations" in the documentation of the RibbonBar
    - Tell in the introduction of that control to use the RibbonView

    Dead simple.
    Thank you,
    John.
  13. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 12 Oct 2011 Link to this post

    Hi John,

    As we replied in your other support ticket , we will update the RadRibbonBar documentation to list its known limitations and to point our customers to the new RadRibbonView control.

    The updated documentation will go live next week. Thank you for your feedback again.

    Best wishes,
    Petar Mladenov
    the Telerik team

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

Back to Top
DevCraft banner