Dude, Where's My Control?
I'm blogging to:
Johnny Cash
The Legend of Johnny Cash
I have received numerous emails from people who are using the Feb CTP version of Crossbow and have run into the bug that we have in ElementHost where the hosted WPF content does not show up until you resize the Form that contains the ElementHost control.
While this may be a small enough issue, many people have requested a work-around for the problem. Well, you would think that all you have to do is force a repaint by calling Invalidate() or Refresh() on the Form, but alas this does not make the content appear. So how can we fix this?
Don't fret my little Crossbow consumers...Uncle Mike is here to hook you up. Here's what you need to do...At the end of your Form_Load() event handler, hook the Shown event and change the Form's size. So, something like:
private void Form1_Load(object sender, EventArgs e) {
ElementHost host = new ElementHost();
host.Dock = DockStyle.Fill;
UserControl1 ctrl = new UserControl1();
host.Controls.Add(ctrl);
this.Controls.Add(host);
// Here's the magic line of code
Shown += delegate { Width++; };
}
This little hack will at least get you up and running so that you can see your hosted WPF content when the Form loads. Generally, this will suffice until you get the version of Crossbow that has this fixed.
Comments
- Anonymous
March 27, 2006
still doesnt work! - Anonymous
March 27, 2006
There is still a problem, we see nothing...
We are (for safety sake) taking youre code and directly pasting it into our project, it still won´t work.
Please, could you post a working project so that we can rule out "code copy" problems.
With kind regards. - Anonymous
March 30, 2006
Are you using the Feb CTP version? And are you using the one that shipped in the Cider directory?
This works fine for me. - Anonymous
April 04, 2006
Yes, we are using Cider and it is the Feb CTP version...
and it still wont work.
With kind regards ;)