locked
Tab key not functioning on form in WPF XBAP application RRS feed

  • Question

  • I'm not really sure which forum this question belongs in as it involves a WinForm application that has been embedded in a WPF XBAP application.

    We originally created a Winform project as a standalone application.  When we open a form in this application, the tab key can be used to move from control to control - i.e., select a textbox on this form, and select the tab key the focus changes to the next textbox (or other control) on the form (which is what we expect and what we want).

    For deployment purposes, we took the original WinForm project and embedded (as a class library) it in a WPF XBAP project.  Everything on the forms seems to function exactly as it did when it was a standalone application with the exception of being able to use the tab key to change the focus to the next control on the form.  The only modifications we had to make to the  original project (other than change it from an application to a class library) to embed it into the WPF XBAP application involved updates to the exit processing on the main form.  Other than that, the code is identitical.

    Development is in C#, Visual Studio 2008 Professional Edition, Version 9.0.30729.1 SP, target .NET 3.5 SP1.


    Mitchell
    Thursday, March 3, 2011 4:40 PM

Answers

  • Hi Mitchell,

    Thanks for the demo.

    I though you are hosting a winform control in a WPF page.

    Since you are opening a winform form from a WPF application, you need to call WindowsFormsHost.EnableWindowsFormsInterop method to forward the keyboard messages.

     

      public Page1()
      {
       InitializeComponent();
       WindowsFormsHost.EnableWindowsFormsInterop();
       tabTestForm.Show();
      }
    

     

    Hope this helps.


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Mitchelll Thursday, March 10, 2011 2:16 PM
    Thursday, March 10, 2011 8:21 AM

All replies

  • I'm not really sure which forum this question belongs in as it involves a WinForm application that has been embedded in a WPF XBAP application.

    We originally created a Winform project as a standalone application.  When we open a form in this application, the tab key can be used to move from control to control - i.e., select a textbox on this form, and select the tab key the focus changes to the next textbox (or other control) on the form (which is what we expect and what we want).

    For deployment purposes, we took the original WinForm project and embedded (as a class library) it in a WPF XBAP project.  Everything on the forms seems to function exactly as it did when it was a standalone application with the exception of being able to use the tab key to change the focus to the next control on the form.  The only modifications we had to make to the  original project (other than change it from an application to a class library) to embed it into the WPF XBAP application involved updates to the exit processing on the main form.  Other than that, the code is identitical.

    Development is in C#, Visual Studio 2008 Professional Edition, Version 9.0.30729.1 SP, target .NET 3.5 SP1.


    Mitchell
    • Merged by Helen Zhou Friday, March 4, 2011 3:21 AM duplicated
    Thursday, March 3, 2011 4:51 PM
  • Hi Mitchell,

    Please don't duplicate posting for the benifit of communite members, I think the question is more suitable in WPF forum as you have posted http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/920664f7-3f9c-4deb-8643-9470afcaf563/
    .(and your initial post on Deployment forum:http://social.msdn.microsoft.com/Forums/en-US/winformssetup/thread/76d7adce-f14c-4b38-ba33-9baf32c395b7), so I will merge this thread to the one on WPF forum, thank you for your understanding.

    Best regards,


    Helen Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 4, 2011 3:21 AM
  • Hi Mitchell,

    Thanks for posting.

    This is interesting. As far as I know, the Tab navigation of embedded WinForm controls is supported in WPF. I have never seen such issue before.

    Does this problem only happens to one particular WinForm control? If this problem can be reproduced, could you please share a small demo project with us?

    If this problem only happens to one particular control, I know it functions well when it was a standalone winform application, but since you have probably changed it to a control, I am wondering how it behaves if you host this control in a winform application instead of a XBap.

    Looking forward to hearing from you.

    Have a nice day!


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 4, 2011 6:20 AM
  • Helen,

    I posted the question on multiple forums based on your recommendation in your reply to my initial post.  You said:  "It seems has few relationship with Deployment but the project itself. I'd suggest you to post the question on Windows forms general forum."  Based on that reply I posted the question to the Winform and WPF forums.  So what exactly is the protocol?  The project involves WinForm, WPF, XBAP, and ClickOnce Deployment so I posted to those forums hoping more people would see it.


    Mitchell
    Friday, March 4, 2011 2:20 PM
  • Min,

    All the documentation I have read also seems to indicate Tab navigation of WinForm controls is supported in WPF.  I did a little more investigation and the tab navigation seems to function correctly on some controls (such as the ComboBox control) but does not function correctly on TextBox controls (which is the primary control we need it for). 

    This problem is occurring on every form in our project.  The project started as a standalone WinForm application; the tab navigation works fine in the standalone WinForm project.  I took that project, copied it to a WPF/XBAP project for hosting, changed it to a class library and included the class library as a reference in the host project.  The TabIndex is set and TabStop is True for each control on every form.  It almost seems as if this functionality is somehow being overridden when the project is embedded in the WPF application.

    I have come up with a workaround but it will require me to set KeyPreview to True on every form, trap every keypress on each form and if it is a tab, force navigatiion to the next control. 


    Mitchell
    Friday, March 4, 2011 2:54 PM
  • Hi Mitchelll,

    Thanks for the update.

    Based on my experience, tab navigation could also works for textbox. Could you please post the xaml/code-behind codes that embed the WinForm control in WPF?

    If you can easily reproduce this problem on your side, could you please share a simple demo of this problem? It would help us identify the cause of the problem.

    Have a nice day!


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 7, 2011 2:10 AM
  • Min,

    We have created a small demo that duplicates the problem; actually, we have created two demos, one is a standalone winform application, and the second is a WPF XBAP application that embeds the original winform application. 

    The winform application contains a single form with 6 textboxes; when the form is displayed and the tab key is pressed, the focus updates to the next textbox in the form.

    I then embedded this application, as is, with no changes (except to change the output type from a windows application to a class library) in a WPF XBAP application.  When this application is executed and the form is displayed, pressing the tab key has no effect.

    What is the process for getting these 2 projects to you? 


    Mitchell
    Monday, March 7, 2011 3:10 PM
  • Hi Mitchell,

    You can reach me at v-minz at microsoft dot com.

    If these demo projects contain confidential/sensitive information, please do not include them in the email. In that case, please let me know your email address.

    Have a nice day.


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 8, 2011 7:14 AM
  • Min,

    The demo projects do not contain any confidential or sensitive information; I'll get them to you this morning.


    Mitchell
    Tuesday, March 8, 2011 1:50 PM
  • Hi Mitchell,

    Thanks for the demo.

    I though you are hosting a winform control in a WPF page.

    Since you are opening a winform form from a WPF application, you need to call WindowsFormsHost.EnableWindowsFormsInterop method to forward the keyboard messages.

     

      public Page1()
      {
       InitializeComponent();
       WindowsFormsHost.EnableWindowsFormsInterop();
       tabTestForm.Show();
      }
    

     

    Hope this helps.


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Mitchelll Thursday, March 10, 2011 2:16 PM
    Thursday, March 10, 2011 8:21 AM
  • Min,

    No, I thought I stated pretty clearly in my first post that we took an entire WinForm application project and "embedded" it (with minimal changes mainly to exit processing) as a class library into a WPF XBAP application for deployment purposes.  I looked back through all of my posts and I don't see anywhere that I indicated we are hosting winform controls on a WPF page.  We are still using all of the forms originally created for the standalone winform application.

    This did correct our problem.

    Thanks.


    Mitchell
    Thursday, March 10, 2011 2:15 PM