Problem

No Keyboard Input in WindowsFormsHost after Interacting with Ribbon TextBox or ComboBox

Posted 1 year ago by Avatar Nathan Hanson

Hi, so this is a weird one so hang in there with me. I'm really stumped and not sure what to do.

I have an application with an Actipro WPF Ribbon Window with a ribbon containing a few ribbon text boxes and combo boxes on it. Then in the document area below the ribbon I have a WinForms control that's hosted inside a WindowsFormsHost object. When I interact with the textbox or the combobox on the ribbon by clicking to change the selection or clicking and typing and then I click the WinForms control to change focus back to it, that WinForms control no longer gets any keyboard input.

It's as if the keystrokes are still going to the ribbon controls and I can't find anyway to get keyboard focus to move back to the WinForms control. I have to restart the app to get the ribbon controls to stop eating the keyboard input. We're getting to within days of shipping our app and I'm running out of ideas. Any thoughts you have would be very welcome. I'm also happy to provide a sample app if that helps.

Thanks in advance!

Nate

[Modified 1 year ago]


Comments (5)

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA

Hi Nate,

I'm sorry you're running into trouble.  I haven't heard of anything like that but WPF/WinForms interop focus can sometimes be wonky.  Can you make a new simple sample project showing this happening so we can debug it and send that over to our support address, referencing this thread?  Please exclude the bin/obj folders from the ZIP and rename the .zip file extension so it doesn't get spam blocked.  Thanks!


Actipro Software Support
Posted 1 year ago by Nathan Hanson

Thanks for the response. As I was building my test app to send in I discovered I'd set 

HwndSource.DefaultAcquireHwndFocusInMenuMode = false;

in my App.xaml.cs. This appears to be what was messing up my keyboard focus for legacy windows in WindowsFormsHost after interacting with the Actipro Ribbon controls. Once I removed that line, keystrokes started flowing again and all is well.

Thanks again for your help and the great components. We're about to ship our brand new, clean. modern UI featuring your Ribbons and Docking and response during beta testing has been very positive. I really appreciate it!

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA

Hi Nathan,

Great, I'm glad you sorted it out and thanks for the comments.  Good luck with your app deployment in the next few days!  And feel free to post a link to some screenshots of it.  We love to see what our customers create with our controls.


Actipro Software Support
Posted 3 months ago by Stefan Wrobel

Hi,

We are currently experiencing the same problem within a similar scenario. (Version is 17.2.0665)

InputManager.IsInMenuMode stays true if I click first in a popup button (or a combobox) within a ribbon and then on an other button within the ribbon.

This only occurs if HwndSource.DefaultAcquireHwndFocusInMenuMode=false, but we need it in combination with Keyboard.DefaultRestoreFocusMode=RestoreFocusMode.None, as explained here. Hence it is not an option for us to set DefaultAcquireHwndFocusInMenuMode to true.

App.xaml.cs:

public App() {
    HwndSource.DefaultAcquireHwndFocusInMenuMode = false;
    Keyboard.DefaultRestoreFocusMode = RestoreFocusMode.None;
}

 MainWindow.xaml:

        <ribbon:Ribbon DockPanel.Dock="Top">
            <ribbon:Ribbon.Tabs>
                <ribbon:Tab Label="Tab 1">
                    <ribbon:Group Label="Group">
                        <ribbon:StackPanel>
                            <ribbon:PopupButton Label="1. Click here" ImageSourceLarge="{StaticResource MyIcon32}">
                                <StackPanel>
                                </StackPanel>
                            </ribbon:PopupButton>
                            <ribbon:Button Label="2. Then click here" ImageSourceLarge="{StaticResource MyIcon32}"/>
                        </ribbon:StackPanel>
                    </ribbon:Group>
                </ribbon:Tab>
            </ribbon:Ribbon.Tabs>
        </ribbon:Ribbon>

        <docking:DockSite>
            <docking:Workspace>
                <docking:TabbedMdiHost>
                    <docking:TabbedMdiContainer>
                        <docking:DocumentWindow Title="MyDocument">
                            <WindowsFormsHost docking:InteropFocusTracking.IsEnabled="True">
                                <WindowsFormsHost.Child>
                                    <wf:TextBox Multiline="True" WordWrap="True" AcceptsReturn="True">
                                        <wf:TextBox.Text>
                                           3. Result: InputManager.Current.IsInMenuMode stays 'true'. WinForms-Controls like this textbox do no longer get any keyboard input.
                                        </wf:TextBox.Text>
                                    </wf:TextBox>
                                </WindowsFormsHost.Child>
                            </WindowsFormsHost>
                        </docking:DocumentWindow>
                    </docking:TabbedMdiContainer>
                </docking:TabbedMdiHost>
            </docking:Workspace>
        </docking:DockSite>

 

I can also provide a complete sample project if that helps.

Could you have a look at this? Thank you!

Stefan

[Modified 3 months ago]

Posted 3 months ago by Actipro Software Support - Cleveland, OH, USA

Hi Stefan,

Thanks for letting us know about this scenario.  I believe we were able to track down the problem and have fixed it for the next build 673.


Actipro Software Support
Information The latest build of this product (2018.1 build 0673) was released 29 days ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.