Coffeehouse Post

Single Post Permalink

View Thread: WPF image control
  • User profile image
    JohnAskew

    I've not gone beyond some simple controls & I've not loaded Vista on any machine yet, which may not be your scenario, but here is some info.

    If you are wanting to use WPF on XP with Windows Forms...
    (aka Crossbow):

    0) Download the .NET 3.0 RC1 and SDK and install them. Get them from here:

    http://msdn.microsoft.com/windowsvista/downloads/products/getthebeta/

    1) Add References to host WPF controls:

     PreesentationCore
     PresentationFramework
     WindowsBase
     WindowsFormsIntegration

    2) Add these using statements to your Form:

    using System.Windows.Forms.Integration;
    using System.Windows.Controls;

    3) To avoid ambiguity with .NET 3.0 UserControls, you must change the inheritance of existing UserControls to be explicitly derived from System.Windows.Forms, like this:

    System.Windows.Forms.UserControl

    4) Put this code in your Form's OnLoad event:

          ElementHost host = new ElementHost();
          System.Windows.Controls.Button myButton =
            new System.Windows.Controls.Button();
          myButton.Content = "Avalon Button";
          host.Child = myButton;
          host.Dock = DockStyle.Fill;
          this.Controls.Add(host);


    You should see "Avalon Button" in your Windows Forms solution.

    The only change from the last WPF release & RC1 is the use of "host.Child" versus "host.Controls.Add()", as far as I can tell.