Why some of my UserControl cannot be displayed on WindowsFormsHost

H

Haiping

Hello,
I use the following code to display some Chart, which is Winforms
UserControl.
I don't know why some chart can be displayed on the WindowsFormsHost but
some chart cannot.

WindowsFormsHost windowsFormsHost = new WindowsFormsHost();
ResultDf1 testChart = new ResultDf1();
windowsFormsHost.Child = testChart ;
myCanvas.Children.Add(windowsFormsHost);

Thanks for any input,
 
N

not_a_commie

There's a variety of things that could go wrong here. Are you setting
the Dock=Fill on your chart? Are you setting Canvas.Top,Left on your
host? Are you setting Width,Height on your host? Does manually calling
Invalidate on your chart cause a redraw?
 
N

not_a_commie

There's a variety of things that could go wrong here. Are you setting
the Dock=Fill on your chart? Are you setting Canvas.Top,Left on your
host? Are you setting Width,Height on your host? Does manually calling
Invalidate on your chart cause a redraw?
 
H

Haiping

Thank you not_a_commie, you answered two of my questions :).

I had set Canvas.Top,Left. I tryed Dock=Fill and Invalidate. They do not
work. I finally figured out that if put line 1 after line 2 and line 3
my1DChart won't show up on the WindowsFormsHost. But I don't know why?

line 1: my1DChart.ShowContextMenu = true;
line 2: Content = myWindowsFormsHost;
line 3: myWindowsFormsHost.Child = myHistogram1DChart;
 
H

Haiping

Thank you not_a_commie, you answered two of my questions :).

I had set Canvas.Top,Left. I tryed Dock=Fill and Invalidate. They do not
work. I finally figured out that if put line 1 after line 2 and line 3
my1DChart won't show up on the WindowsFormsHost. But I don't know why?

line 1: my1DChart.ShowContextMenu = true;
line 2: Content = myWindowsFormsHost;
line 3: myWindowsFormsHost.Child = myHistogram1DChart;
 
H

Haiping

I also found out if your winform control does not have chart inside you need
put it on Winform UserControl first them put the Winform UserControl on
WindowsFormsHost.

Example:
System.Windows.Forms.UserControl userControl = new
System.Windows.Forms.UserControl();
userControl.Controls.Add(myWinformChart);
myWindowsFormsHost.Child = userControl;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top