Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 948471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:15:04+00:00 2026-05-15T23:15:04+00:00

I’m using the Microsofts RibbonControlLibrary for a Ribbonmenu with several RibbonCommands. I have a

  • 0

I’m using the Microsofts RibbonControlLibrary for a Ribbonmenu with several RibbonCommands. I have a TabControl that should contain tabs for each ribbon button pressed. E.g. I click on RibbonCommand 2, I want a tab called “Tab2” be created, if it is not already present in the TabControl, otherwise it should be focused.

I’ve already implemented http://www.codeproject.com/KB/WPF/WpfTabCloseButton.aspx, which are very nice.

I think I still don’t get the event mechanism of WPF quite right. My code strongly adapted the sample project of the Ribboncontrol.

This is how I implemented the Command:

<Window.CommandBindings>
  <CommandBinding Command="me:AppCommands.Protokoll" Executed="RibbonButton_Click" /> 
</Window.CommandBindings>

The button inside the RibbonControl looks like the following.

<r:RibbonButton Command="me:AppCommands.Protokoll" />

AppCommands.cs

public class AppCommands
{
  public static RibbonCommand Protokoll
  {
     get { return (RibbonCommand)Application.Current.Resources["ProtokollCommand"]; }
   }
}

ResourceDictionary:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary">
    <r:RibbonCommand x:Key="ProtokollCommand"                
        LabelTitle="foo"
        ToolTipTitle="foo"
        ToolTipDescription="foo" />
</ResourceDictionary>

What I now want to write is a Method that creates a Tab for each button click, where as the created tabpage contains specific usercontrols. I do not know, how to best implement the mapping between the CommandButtons and the Tabs. I think its best to use just one click-eventhandler rather than a eventhandler for each button.
Questions:

1) How can I find out which unique button raised the event? I’ve only managed to get the information in the ResourceDictionary. Unfortunatly there is no such property as uniqueID or something like this.
I’ve done this with:

private void RibbonButton_Click(object sender, RoutedEventArgs e)
{
  // ((Microsoft.Windows.Controls.Ribbon.RibbonCommand)(((System.Windows.Controls.Button)(e.OriginalSource)).Command))
}

I do not want to create a mapping based on a property like LabelTitle that is supposed for display.

2)
I’ve found this WPF/C#: How does one reference TabItems inside a TabControl? which showed me how to query the Items collection of the TabControl. Is that a good attempt or is there a better one?

3)
How should I create the mapping between the RibbonCommand and the TabPage + Controls that should be displayed. Of course I could use a Dictionary like

Dictionary<String, fooContainer>
// ...
public class fooContainer()
{
  public String TabHeaderString {get;set;}
 // other properties
}

Or does WPF present a better approach with these ResourceDictionaries, that I haven’t understood till now.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:15:04+00:00Added an answer on May 15, 2026 at 11:15 pm

    Since you are using a Command to manage the tabs, I suppose you could set the CommandParameter property of each Button in a meaningful way, so that it is possible to discriminate among the different actions you need to achieve (i.e. it could be an Enum, if you already know the kind of tabs you need to expose, or a more complex object in case such tabs can be created dynamically).

    By the way, the signature of the RibbonButton_Click method doesn’t look correct to me, since the arguments passed to the method should be of type ExecutedRoutedEventHandler. Doing so will allow you to access the CommandParameter specified at the Button level, through the Parameter property of the args variable.
    Following the code to modify:

    1. Add a proper CommandParameter to your RibbonButton

    <r:RibbonButton Command="me:AppCommands.Protokoll" CommandParameter="TabKind.Sample1"/>
    <r:RibbonButton Command="me:AppCommands.Protokoll" CommandParameter="TabKind.Sample2"/>
    

    2. Change the handler to the Execute event, to match a proper signature, and handle the parameter according to your needs

    private void RibbonButton_Click(object sender, ExecutedRoutedEventArgs e)
    {
      TabKind kind = (TabKind)e.Parameter;
      switch (kind)
      {
           case TabKind.Sample1:
           {
               //Do something meaningful...
               break;
           }
           case TabKind.Sample2:
           {
               //Do something meaningful...
               break;
           }
      }
    }
    

    To answer you questions directly:

    1. You shouldn’t need to know which instance of the button raised the Command, the proper way is to use a CommandParameter to identify what kind of action you want to perform (the RibbonButton is just the host of the Command, doesn’t make senso to me to design the logic of the application to the specific UI implementation).

    2. If you really need to query the TacControl for its TabItemchildren, the link you provided is of course the way to go.

    3. Once you have identified the action you need to perform, you could retrieve the instance of the TabItem you need through a register you previously created (i.e. you can have a proper Dictionary used to associate the Enum value with a TabItem instance). Another possible way, is to use the Tag property on each TabItem, set it to a proper Enum value and use the following method to retrieve the proper TabItem (note that kind is the variable defined in the previous snippet):

    TabItem matchingItem = tab_main.Items.Cast<TabItem>()
                                         .Where(item => item.Tag == kind)
                                         .FirstOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.