How can I place image control or any control dynamically with WPF?
-
-
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
-
I'm very early along my WPF book, but can't you do something like...
c.Content = theImage;
? -
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. -
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 -
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 -
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
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.