Coffeehouse Thread

8 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

how to WPF in Windows.Forms with .NET 3.0 RC1

Back to Forum: Coffeehouse
  • User profile image
    JohnAskew

    This is fun+cool, daddy-o.

    Start experimenting WPF on XP:

    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 these References to projects you want 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, explicitly state namespaces for controls like 'Button' and 'ListBox':

       System.Windows.Forms.Button      // .NET 2.0
       System.Windows.Controls.Button  // .NET 3.0


    4) Place two Panels on your Form from the ToolBox.

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

    ElementHost hostListBox = new ElementHost();
    System.Windows.Controls.
    ListBox wpfListBox =
        new System.Windows.Controls.ListBox();

    for
    (int i = 0; i < 10; i++)
        wpfListBox.Items.Add(
    "Item " + i.ToString());

    hostListBox.Dock =
    DockStyle.Fill;
    hostListBox.Child = wpfListBox;

    ElementHost
    hostButton = new ElementHost();
    System.Windows.Controls.
    Button wpfButton =
        new System.Windows.Controls.Button();

    wpfButton.Content =
    "Avalon Button";
    hostButton.Dock =
    DockStyle.Fill;
    hostButton.Child = wpfButton;

    this.panel1.Controls.Add(hostListBox);
    this.panel2.Controls.Add(hostButton);



  • User profile image
    Minh

    JohnAskew wrote:
    
    3) To avoid ambiguity, explicitly state namespaces for controls like 'Button' and 'ListBox':

       System.Windows.Forms.Button      // .NET 2.0
       System.Windows.Controls.Button  // .NET 3.0



    Or another way is:

    using N2 = System.Windows.Forms;
    using N3 = System.Windows.Controls;

    N2.Button b2 = ...
    N3.Button b3 = ...

  • User profile image
    Rob Relyea

    jfoscoding just posted a set of articles about WPF from a Windows Forms perspective.


    Check out this other thread on Channel 9 with a list of some resources as well...

    Thanks, Rob Relyea
    Program Manager, WPF Team
    http://rrelyea.spaces.live.com

  • User profile image
    Jack Poison

    Is there a way to instantiate .NET 3.0 RC1 WPF items from a .NET 1.1 Winform?

  • User profile image
    cwilliams11​45

    Minh wrote:
    
    JohnAskew wrote:
    3) To avoid ambiguity, explicitly state namespaces for controls like 'Button' and 'ListBox':

       System.Windows.Forms.Button      // .NET 2.0
       System.Windows.Controls.Button  // .NET 3.0



    Or another way is:

    using N2 = System.Windows.Forms;
    using N3 = System.Windows.Controls;

    N2.Button b2 = ...
    N3.Button b3 = ...


    Perhaps something like this would be clearer in code:

    using Forms = System.Windows.Forms;
    using Wpf = System.Windows.Controls;

  • User profile image
    Rob Relyea

    Jack Poison wrote:
    Is there a way to instantiate .NET 3.0 RC1 WPF items from a .NET 1.1 Winform?


    Not within the same process. WPF is built on CLR v2 and therefore isn't compatibile with CLR v1.1.

    Thanks, Rob

  • User profile image
    dahat

    Rob Relyea wrote:
    
    Jack Poison wrote: Is there a way to instantiate .NET 3.0 RC1 WPF items from a .NET 1.1 Winform?


    Not within the same process. WPF is built on CLR v2 and therefore isn't compatibile with CLR v1.1.

    Thanks, Rob


    There is a way... or at least I expect that there is as I've come up with a little hack to allow the use of 2.0 classes within an 1.1 app and it should be possible to also have it apply to 3.0... one of these days I'll finish the write up on it.

  • User profile image
    Jack Poison

    See, I'm locked into a 1.1 form.  But, the box has the 2.0 and 3.0 Framework on it, so I"m wondering if there isn't a Hack for this. I don't need it on a production machine, only for a demonstration.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.