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

  • Home
  • SEARCH
  • 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 6611481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:58:30+00:00 2026-05-25T19:58:30+00:00

Given: <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width=* /> <ColumnDefinition Width=* /> </Grid.ColumnDefinitions> <Grid.CommandBindings> <CommandBinding Command=Cut Executed=CommandBinding_Executed/>

  • 0

Given:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

    <Grid.CommandBindings>
        <CommandBinding Command="Cut" 
                        Executed="CommandBinding_Executed"/>
    </Grid.CommandBindings>

    <TextBox x:Name="WpfTextBox" 
             VerticalAlignment="Center" 
             Text="Hello there" />

    <WindowsFormsHost Grid.Column="1" 
                      VerticalAlignment="Center">
        <wf:TextBox x:Name="WinFormsTextBox" 
                    Text="Hello there" />
    </WindowsFormsHost>
</Grid>

Pressing Ctrl+X in WinFormsTextBox causes CommandBinding_Executed to fire, but not when you are in WpfTextBox.

I wish to have the behaviour of WpfTextBox for WinFormsTextBox. I.e. The command should only fire when nothing has focus – it should work like a global view command or something.

Note: Adding a handler to the command’s CanExecute event only aids in either preventing anything from happening in the WinFormsTextBox (Ctrl+X is completely swallowed when e.CanExecute is set to true – meaning no text is cut), or performs as normal.

Note 2: Cut is only an example, I would like a solution that would work for any command binding.

Note 3: The command should be able to fire from another control, if it had focus – like a ListView or something. Unless it had a TextBox that had focus inside of it (think edit mode).

I am not sure anything can really be done, I don’t want to accept having to add specific handling in the CommandBinding_Executed method. But, C’est la vie.

  • 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-25T19:58:31+00:00Added an answer on May 25, 2026 at 7:58 pm

    A slightly silly solution for a slightly silly problem. This is a simple version of my final solution:

    private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
    {
        e.ContinueRouting = IsFocusInWinFormsInputControl();
    }
    
    private static bool IsFocusInWinFormsInputControl()
    {
        // Try get focus control
        WinForms.Control focusedWinFormsControl = GetFocusedWinFormsControl();
    
        // Is there anything and is it a textbox etc?
        return focusedWinFormsControl != null &&
            (focusedWinFormsControl is WinForms.TextBox ||
             focusedWinFormsControl is WinForms.RichTextBox);
    }
    
    private static WinForms.Control GetFocusedWinFormsControl()
    {
        // Try get focused WinForms control
        IntPtr focusedControlHandle = GetFocus();
    
        WinForms.Control focusedControl = null;
        if (focusedControlHandle != IntPtr.Zero)
        {
            // Note: If focused Control is not a WinForms control, this will return null
            focusedControl = WinForms.Control.FromHandle(focusedControlHandle);
        }
    
        return focusedControl;
    }
    
    [DllImport("user32.dll")]
    private static extern IntPtr GetFocus();
    

    Basically, add in command validation logic to only execute the command if we are outside a WinForms TextBox.

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

Sidebar

Related Questions

Given a simple Silverlight Grid like this: <Grid ShowGridLines=True> <Grid.ColumnDefinitions> <ColumnDefinition x:Name=MyColumn Width=2* />
I have the following ControlTemplate : <ControlTemplate> <Grid VerticalAlignment=Stretch HorizontalAlignment=Left Width=400> <Grid.ColumnDefinitions> <ColumnDefinition Width=18
Here's the XAML: <ListBox Grid.Row=1 x:Name=lstGames Background=#343434 > <ListBox.ItemTemplate> <DataTemplate> <Grid ShowGridLines=True> <Grid.ColumnDefinitions> <ColumnDefinition
Given the following little snippet: <Grid> <Frame Width=300 Height=300 Background=Blue></Frame> <Frame Width=350 Height=350 Background=Red></Frame>
Given a basic grid (like a piece of graph paper), where each cell has
Given this XAML: <StackPanel Orientation=Horizontal Grid.Row=1 Grid.Column=0 Margin=5> How can I assign the Grid.Row
I've been given a prototype/mockup of a grid written in html and javascript (via
Today a work mate posed a question to me. Given a grid of characters
Given an array of 81 elements (meant to represent a 9x9 grid) how can
Given a Grid , I'm adding a child to it using Grid.Children.Add(element) . How

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.