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 6654961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:27:18+00:00 2026-05-26T01:27:18+00:00

I have a window that has some tabs,in each tab i can create a

  • 0

I have a window that has some tabs,in each tab i can create a new item.
I want define a short key for create new item.But i want my short Key work on active tab.
For example, when Tab1 was active my short key work on create item in Tab1 or when Tab2 was active my short key work on create item in Tab2. How can i use from one short key on active tab?

  • 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-26T01:27:18+00:00Added an answer on May 26, 2026 at 1:27 am

    There are many ways to accomplish this. The most common is to use a command. First, here’s the XAML I used:

    <Grid>
        <TabControl Grid.Row="0"
                    x:Name="AppTabs">
            <TabItem Header="Tab 1">
                <ListBox x:Name="TabOneList" />
            </TabItem>
    
            <TabItem Header="Tab 2">
                <ListBox x:Name="TabTwoList" />
            </TabItem>
        </TabControl>
    </Grid>
    

    Here’s the code-behind:

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        // create the new item command and set it to the shortcut Ctrl + N
        var newItemCommand = new RoutedUICommand("New Item", "Makes a new item on the current tab", typeof(MainWindow));
        newItemCommand.InputGestures.Add(new KeyGesture(Key.N, ModifierKeys.Control, "Ctrl + N"));
    
        // create the command binding and add it to the CommandBindings collection
        var newItemCommandBinding = new CommandBinding(newItemCommand);
        newItemCommandBinding.Executed += new ExecutedRoutedEventHandler(newItemCommandBinding_Executed);
        CommandBindings.Add(newItemCommandBinding);
    }
    
    private void newItemCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
    {
        // one way to get the ListBox control from the currently selected tab
        ListBox itemList = null;
        if (AppTabs.SelectedIndex == 0)
            itemList = this.TabOneList;
        else if (AppTabs.SelectedIndex == 1)
            itemList = this.TabTwoList;
    
        if (itemList == null)
            return;
    
        itemList.Items.Add("New Item");
    }
    

    I wouldn’t consider this production code, but hopefully it points you in the right direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HUD window that has some labels on it, and I want
I have a WPF window( using c# as code behind) that has some text
I have Window that has a ListBox ListBox(MyListBox) has a DataTable for its DataContext
I have a Window that has two primary areas. One is a TextBox inside
In WPF I have one window opening a second window that allows some data
I have a live db that has some 2011 dates that were entered as
So I have this UIWindow that has some custom properties. I also have a
I have a pyglet window that has a attribute observer. The observer has a
I have a small application that has a message only WTL window which does
I have a form that opens at startup (frmStart). That form has some code

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.