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

Bind RibbonTab to Command

8 Answers 271 Views
RibbonView and RibbonWindow
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 05 Oct 2011, 05:43 PM
Hello!
How to bind the radribbon tab to a command?
like ... <RadRibbonTab Command="{Binding MyCommand}"...>

Thanks.

8 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 10 Oct 2011, 04:34 PM
Hi Daniel,

The RadRibbonTab control doesn't expose a Command property. I am not sure what you need to implement, but if you want to execute custom logic when selecting a RibbonTab, you can handle the RadRibbonView SelectionChanged event or you can use an InvokeCommandAction to attach a Command to the SelectionChanged event and you can also pass the selected RadRibbonTab as a parameter to the command.

Greetings,
Tina Stancheva
the Telerik team

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

0
Ram
Top achievements
Rank 1
answered on 08 Dec 2014, 09:41 PM
Hi,

I have implemented the SelectionChanged event on the RadRibbonView for dynamically changing a ContentControl based on the active RibbonTab. The event also gets raised when the minimize button is clicked.

1) Is there a way to prevent the event getting called on click of minimize button
or
2) Handle the SelectionChanged event so that it does not raise an exception when the SelectedItem is called


My View Model code
================

RadRibbonTabSelectionChangedCommand = new DelegateCommand<object>(OnRibbonTabSelectionChanged);       

private void OnRibbonTabSelectionChanged(object e)
        {
            if (e is RadSelectionChangedEventArgs)
            {
                RadRibbonView ribbon = (e as RadSelectionChangedEventArgs).Source as RadRibbonView;
                if (ribbon == null) return;                var ribbonTab = ribbon.SelectedItem;                //Get the default container and using the container get the singleton region manager
                var container = ServiceLocator.Current.GetInstance<IUnityContainer>();
                var regionManager = container.Resolve<IRegionManager>();                string header = (ribbonTab as RadRibbonTab).Header.ToString();
                Uri uri = null;
                switch (header)
                {
                    case "Tab1":
                        uri = new Uri("Module1.Views.Home", UriKind.Relative);
                        break;
                    case "Tab2":
                        uri = new Uri("Module2.Views.Home", UriKind.Relative);
                        break;
                }
                if (uri != null)
                    regionManager.RequestNavigate("MainRegion", uri);
            }
        }

My View code
===========
      
<telerik:RadRibbonView x:Name="MainRadRibbon"
                               Title="MyTitle" ApplicationName="MyApplication"
                               MinimizeButtonVisibility="Visible"
                               HelpButtonVisibility="Visible" HelpButtonImageSource="{StaticResource HelpImageSource}"
                               prism:RegionManager.RegionName="RadRibbonRegion" />
            <interactivity:Interaction.Triggers>
                <interactivity:EventTrigger EventName="SelectionChanged">
                    <prism:InvokeCommandAction Command="{Binding RadRibbonTabSelectionChangedCommand}" />
                </interactivity:EventTrigger>
            </interactivity:Interaction.Triggers>        </telerik:RadRibbonView> 

<ContentControl prism:RegionManager.RegionName="MainRegion"></ContentControl>
0
Milena
Telerik team
answered on 10 Dec 2014, 11:59 AM
Hello Ram,

Thank you for the code snippet provided.

Let me get straight to your questions: 
1) There is no way to prevent the rising of SelectionChanged event, when the Minimized button is clicked.
2) When the ribbonView is minimized, the ribbonView.SelectedItem is null (and the ribbonView.SelectedIndex = -1). This is the reason for getting an exception (you try to get the header of the ribbonTab, which is null at this moment). 

So, you can add a check for the SelectiedItem in your code to ensure that your logic won't be executed when the ribbonView is minimized: 
var ribbonTab = ribbon.SelectedItem;
if (ribbonTab != null)
{
    string header = (ribbonTab as RadRibbonTab).Header.ToString();
    Uri uri = null;
    switch (header)
    {
        case "Tab1":
            uri = new Uri("Module1.Views.Home", UriKind.Relative);
            break;
        case "Tab2":
            uri = new Uri("Module2.Views.Home", UriKind.Relative);
            break;
    }
}

I hope this information is helpful. Please don't hesitate to write us back if you have more questions.

Regards,
Milena
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ram
Top achievements
Rank 1
answered on 10 Dec 2014, 01:58 PM
Thanks for your reply.

Further to the above issue, when I double-click on the ribbon tab to minimize, the SelectionChanged event is raised and the SelectedItem is null again.

To fix this, I have added at the start of the method -

if ((e as RadSelectionChangedEventArgs).AddedItems.Count == 0) return;

Now when you double-click again to expand, the SelectionChanged event is raised twice. But the ribbon does not expand in debug mode. Is there a way to prevent it from calling the second time and how to fix the re-expand issue.

Thanks

0
Milena
Telerik team
answered on 11 Dec 2014, 11:59 AM
Hello Ram,

I tried to reproduce the described by you behavior following you code, but it works as expected on our side. However I attached the test project I used. Please feel free to modify it in order to show us how to reproduce the described behavior of the RadRibbonView. 

Also please have in mind that I used our EventToCommandBehavior instead of PRISM InvokeCommandAction for the command and for this reason I've tested it with the latest version of our UI for WPF (you can find trial dlls in the project). You can take a look at it and see if you can reproduced the issue with the sent project.

I am looking forward to helping you solve this issue.

Regards,
Milena
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ram
Top achievements
Rank 1
answered on 11 Dec 2014, 02:13 PM
Hello Milena,

I ran your project in debug mode by setting a breakpoint on the OnRibbonTabSelectionChanged method and the issue can be reproduced. I have not made any changes in the code or DLL references.

Steps to reproduce -
1) Set a breapoint on the OnRibbonTabSelectionChanged method
2) Run the project in debug mode and the breakpoint will be hit => no issues
3) Double-click on Home tab to minimize the RibbonView => hits the breakpoint and works fine, no issues
4) Now double-click again on Home tab to expand the RibbonView => the method will be raised twice but the RibbonView does not expand.

Thanks
0
Milena
Telerik team
answered on 15 Dec 2014, 09:29 AM
Hi Ram,

Thank you for the steps, I understand your scenario now.

Let me try to explain how does the minimization functionality of the RadRibbonView working.
1) To minimize the ribbon you should: double click on any of the tab headers or choose "Minimize the Ribbon" under the Quick Access Tool bar menu (QAT)
2) To restore and pin the ribbon you should: again double click on any of the tab headers or choose 
"Restore the Ribbon" from QAT.
3) If the ribbon is minimized and you single click on some of the tab headers, the ribbon is restored again, but not pined. And then if you click once again, the ribbon becomes minimized (because it is not pined).

So, when you set the breakpoint at the beginning of the event, the Visual Studio gets the focus and the ribbon considers the double click as 2 single clicks. I suggest you to set the breakpoint after this row: 
private void OnRibbonTabSelectionChanged(object e)
{
    if ((e as RadSelectionChangedEventArgs).AddedItems.Count == 0) return;
 
      ... // breakpoint

So you can skip the first raising of the event.

Let me know if there is anything else I can assist you with.

Regards,
Milena
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ram
Top achievements
Rank 1
answered on 15 Dec 2014, 06:53 PM
Thanks for clarifying. You may close this issue.
Tags
RibbonView and RibbonWindow
Asked by
Daniel
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Ram
Top achievements
Rank 1
Milena
Telerik team
Share this question
or