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

The Archive Base Latest Questions

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

As the title describes, I want to convert System.Windows.Controls.Textbox to IWin32Window. I read How

  • 0

As the title describes, I want to convert System.Windows.Controls.Textbox to IWin32Window.
I read How to use a FolderBrowserDialog from a WPF application
but it only describes how to get handle of winform, not control on it.

Thanks

  • 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-16T09:58:31+00:00Added an answer on May 16, 2026 at 9:58 am

    WPF does not use Win32 handles for individual controls like TextBox, only for the Window itself. In other words, from Win32’s perspective the entire WPF Window object is a single window with single handle.

    Because of this, it is meaningless for an IWin32Window to return the “actual” Win32 handle of a WPF TextBox: A WPF TextBox simply doesn’t have a Win32 handles. Thus you will have to return a Win32 handle of some other object.

    How to do this depends on what you will be using the IWin32Window for. There are several possibilities for creating a Win32 window to correspond to your TextBox:

    1. You could create a transparent Win32 window that overlaps the TextBox (useful for hit-testing or overdrawing scenarios)
    2. You could create a zero-size window that is centered on the TextBox (useful for dialog initial-location and ownership scenarios)
    3. You could host the TextBox in an ElementHost rather than in a WPF Window (useful if you want the TextBox to fit in with other Win32 stuff, such as an old MFC application)
    4. You could host the TextBox in an ElementHost inside a WindowsFormsHost (useful if you need a Win32 window around the TextBox but still need WPF layout

    Notes on the “extra window” solutions (1 & 2)

    To create a Win32 window that overlays the TextBox (either transparent or zero-size), you would use traditional Win32 or WinForms techniques.

    Since the TextBox can move on the screen you would need to move the Win32 window whenever the TextBox moves. This can be done in the OnRendering event using textBox.TransformToAncestor(window) then transforming to device coordinates using PresentationSource.TransformToDevice.

    Notes on ElementHost solutions (3 & 4)

    This is as simple as wrapping the ElementHost around the TextBox in your XAML, so this:

    <Grid>
      ...
      <TextBox ...>
    </Grid>
    

    might become:

    <Grid>
      ...
      <WindowsFormsHost>
        <ElementHost>
          <TextBox ...>
        </ElementHost>
      </WindowsFormsHost>
    </Grid>
    

    This can also be done in code by removing the TextBox from its parent, adding it to a newly-created ElementHost, and then adding the ElementHost to a newly-created WindowsFormsHost and adding the WindowsFormsHost back to the parent.

    Note that WPF styles and properties (including DataContext, TextElement properties, etc) do not propagate down through ElementHost, even if wrapped inside a WindowsFormsHost, so the desired settings and resources must be propagated manually.

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

Sidebar

Related Questions

Not entirely sure my question title describes what I want to do, but couldn't
The title describes it at best. I want to switch back to a default
I am not sure if title describes what i want accurately. What i want
Like described in the title, I want to open a native ios viewcontroller when
As the title describes, I'm trying to group up a grid of 3x3 radio
As the title describes. I need to see if the machine accessing my page
don't know if the title describes anything about what I'm trying to say but
I have a UITableView that has five sections. Just as the title describes cellForRowAtIndexPath
I hope the title actually describes what I wanted to ask... I wrote a
Not sure the title fully describes the problem/question I'm trying to ask, sorry. One

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.