Coffeehouse Thread

7 posts

Forum Read Only

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

WPF image control

Back to Forum: Coffeehouse
  • User profile image
    vennag

    How can I place image control or any control dynamically with WPF?

  • User profile image
    Cybermagell​an

    vennag wrote:
    

    How can I place image control or any control dynamically with WPF?



    I haven't looked at WPF...but maybe try something like

    <image src="" /> or something similar?

    That's how we do it in Boxely

  • User profile image
    Minh

    I'm very early along my WPF book, but can't you do something like...

    c.Content = theImage;

    ?

  • 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.

  • User profile image
    Harlequin

    Minh wrote:
    I'm very early along my WPF book, but can't you do something like...

    c.Content = theImage;


    Charles Petzolds book? I'm close to finishing just chapter 1 and I've learned tons.....hehe

  • User profile image
    Ernie Booth

    vennag wrote:
    

    How can I place image control or any control dynamically with WPF?



    It depends on your layout panel.  If your parent is a Canvas then you would write some code like this:

    Canvas.SetLeft(controlToPosition, 30.3);
    Canvas.SetTop(controlToPosition, 100);

    if it's a grid then you would set Row and Column

    Grid.SetRow(controlToPosition, 2);
    Grid.SetColumn(controlToPosition, 0);

    - Ernie

  • User profile image
    Minh

    Harlequin wrote:
    
    Minh wrote:I'm very early along my WPF book, but can't you do something like...

    c.Content = theImage;


    Charles Petzolds book? I'm close to finishing just chapter 1 and I've learned tons.....hehe

    Hehe! Yep! I think I'm on chapter 3... but I did skip a lot of the rainbow gradient brushes in Ch. 2 Smiley

Conversation locked

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