WindowsFormsHost Winform pdfviewer control problem

I have a wpf Usercontrol, inside i am using a Winforms pdfviewer to display pdf files. Also i have couple of Textboxes to enter document details. finally, A popup which display this user control. The problem is, when i try to type something in textboxes, ntn is happenning. when i right click on a textbox, i can see context menu with cut, copy and paste options. After googling little bit, i found something like below, Forms.Integration.WindowsFormsHost.EnableWindowsFormsInterop(), I placed this line in loaded event but this is not working. can any one faced simillar issue and have any solutions. Thanks. Rey


I ran into this problem a while back. As I recall it was a bug having to do with the top level WPF message loop not playing nice with the WinForms message loop.

The solution I used was to change my outermost layer from a WPF Window to a WinForms Form. In other words, I replaced

new Window { Content = CreateContent(), Title = title }.Show();


new ElementHostForm(CreateContent(), title).Show();

by using a class like this:

class ElementHostForm : System.Windows.Forms.Form
  ElementHost _host;

  public WinFormsWindow(UIElement content, string title)
    _host = new ElementHost { Child = content };

    content.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
    if(content.DesiredSize.Width > 100 && content.DesiredSize.Height > 100)
      ClientSize = _host.Size =
        new Size((int)content.DesiredSize.Width, (int)content.DesiredSize.Height));


    Title = title;

  protected override void OnResize(EventArgs e)
    if(!ClientSize.IsEmpty) _host.Size = ClientSize;

This worked around the bug by allowing WinForms to have the outermost message loop.

This change was very easy for me because I already had my top-level content in a separate UserControl (not a Window). If your top-level content is a Window you may need to refactor.

Need Your Help

Confused with NullPointerException

nullpointerexception android-activity onclicklistener

I know that i am probably missing something simple but i am getting this error when i try to load my second activity and i have no idea why, I understand (Or iv'e been told) That it happens when your

Rails Partial (Rails 3, HAML) arbitrarily slow

ruby-on-rails ruby ruby-on-rails-3 haml mongrel

I'm using Rails 3.0.1, HAML 0.3.22, and Mongrel 1.1.5 (and MongoMapper not AR). I'm rendering a list, and each list item is it's own partial. Every time the page renders one of the list item partials

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.