Posted By: vennag | Oct 25th, 2006 @ 12:26 PM
page 1 of 1
Comments: 6 | Views: 2724

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

Cybermagellan
Cybermagellan
Live for nothing, or die for everything
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
Minh
Minh
WOOH! WOOH!
I'm very early along my WPF book, but can't you do something like...

c.Content = theImage;

?
JohnAskew
JohnAskew
9 girl in pink sweater
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.
Harlequin
Harlequin
http://twitter.c​om/TrueHarlequin
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
Ernie Booth
Ernie Booth
The Electron Sculptor
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
Minh
Minh
WOOH! WOOH!
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
page 1 of 1
Comments: 6 | Views: 2724
Microsoft Communities