Getting input from a RadWindow in a WinForms app

9 posts, 1 answers
  1. Jason
    Jason avatar
    47 posts
    Member since:
    Jan 2013

    Posted 14 Jan 2015 Link to this post

    I've had a look, but can't see anything about other people having this particular issue.

    We have a WPF library that contains a RadWindow with a textbox, requiring user input. 
    We then have a WinForms application that creates and show this RadWindow.
    When we try to type in the textbox, nothing happens.

    If we use a regular WPF window for the dialog, then we can use the ElementHost.EnableModelessKeyboardInterop() function, which makes everything work as expected. However, the RadWindow isn't actually a window, so we can't use this method.

    So how do we resolve this issue?

    Thanks
    Jason
  2. christianamado
    christianamado avatar
    8 posts
    Member since:
    May 2014

    Posted 14 Jan 2015 in reply to Jason Link to this post

    Have you tried this:
    1.yourRadWindow.Owner = this;

    Hope it helps in any way.

    Regards.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Jason
    Jason avatar
    47 posts
    Member since:
    Jan 2013

    Posted 14 Jan 2015 in reply to christianamado Link to this post

    What type are you expecting this to be?

    For a RadWindow, the Owner needs to be a ContentControl. If this is the mainform, then the type is a Windows.Forms, which doesn't work as a RadWindow owner.
  5. Answer
    Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 15 Jan 2015 Link to this post

    Hello Jason,

    RadWindow is hosted in native WPF Window, so you would need to get its host in order enable the keyboard. This should be done after RadWindow is loaded - so you can hook to the Loaded event of get the parent WPF Window as shown below:
    void radWind_Loaded(object sender, RoutedEventArgs e)
    {
        var radWindow = sender as RadWindow;
        var window = Window.GetWindow(radWindow);
        ElementHost.EnableModelessKeyboardInterop(window);
    }

    Hope this will work for you.

    Regards,
    Kalin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Jason
    Jason avatar
    47 posts
    Member since:
    Jan 2013

    Posted 15 Jan 2015 in reply to Kalin Link to this post

    Perfect. And something that I'm sure I can use elsewhere.

    Thanks
  7. Jason
    Jason avatar
    47 posts
    Member since:
    Jan 2013

    Posted 10 Mar 2015 Link to this post

    I have a secondary problem relating to this. I am attempting to set the owner of the dialog to the main WinForm, using code similar to 

        var wpfWindow = Window.GetWindow(lclDlg);
        if (wpfWindow != null)
        {
            var helper = new WindowInteropHelper(wpfWindow) { Owner = ownerFrm.Handle };
        }

    I have this in the dialog loaded event, since that's when GetWindow actually works. However, the .NET framework then complains that you can't set the owner of a dialog once it's already been shown.

    Any solution?


  8. christianamado
    christianamado avatar
    8 posts
    Member since:
    May 2014

    Posted 10 Mar 2015 in reply to Jason Link to this post

    Hi Jason, I think that your snippet must be something like this:
    //Win32 HWND
    var wpfWindow = Window.GetWindow(lclDlg); //getting you actual window
    if (wpfWindow != null)
    {
        var helper = new WindowInteropHelper(wpfWindow);
        helper.Owner = wpfWindow.Handle; //get your Win32 HWND
        wpfWindow.ShowDialog();
    }
     
    //WPF directly
    var wpfWindow = Window.GetWindow(YOUR DESIRED WINDOW);
    if (wpfWindow != null)
    {
        wpfWindow.Owner = App.Current.MainWindow;
        wpfWindow.ShowDialog();
    }

    Hope it helps.

    Regards.
  9. Jason
    Jason avatar
    47 posts
    Member since:
    Jan 2013

    Posted 10 Mar 2015 in reply to christianamado Link to this post

    Unfortunately, that doesn't help the Win32 situation.

    Window.GetWindow doesn't return anything until you've shown the dialog (from what I can tell), so you can't set the owner. WPF doesn't matter, since you can set a WPF parent on a WPF RadWindow before it's created
  10. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 13 Mar 2015 Link to this post

    Hello Jason,

    Unfortunately you it is not possible to set the owner after the dialog is already shown. However if you display RadWindow using the Show() method you will be able to set it on Loaded.

    I hope not using dialog Window will be suitable for you.

    Regards,
    Kalin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready