ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  ChartDirector .NET control under WPF WindowsFormsHost
Posted by Julian Lindars on Feb-19-2011 02:12
Hi,

Could anyone tell me the best way to add a ChartDirector chart to WPF application using the WindowsFormsHost?

Is this possible using XAML?

I have added the WinChartViewer to the Windows Forms Toolbox, and in my WPF app I have added the namespace
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
However the WinChartViewer is not recognised as part of the wf namespace

Thanks in advance,

Julian

  Re: ChartDirector .NET control under WPF WindowsFormsHost
Posted by Peter Kwan on Feb-19-2011 08:41
Hi Julian,

You may try the following steps:

1. Add reference to:

System.Windows.Forms
WindowsFormsIntegration
System.Drawing
System.Web
netchartdir.dll

2. Drag a WindowsFormsHost to the design surface

3. Use (in VB.NET):

Imports ChartDirector

Dim ChartViewer1 As WinChartViewer = New WinChartViewer()
ChartViewer1.ChartSizeMode = WinChartSizeMode.StretchImage
WindowsFormsHost1.Child = ChartViewer1

... create chart and use WinChartViewer as usual ...

Hope this can help.

Regards
Peter Kwan

  Re: ChartDirector .NET control under WPF WindowsFormsHost
Posted by Julian Lindars on Feb-22-2011 19:35
Thanks!

Converting this to C# I have the following:
(after adding reference to netchartdir.dll)

using ChartDirector;
...

namespace WpfTest
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            WinChartViewer chartViewer1 = new WinChartViewer();
            chartViewer1.ChartSizeMode = WinChartSizeMode.StretchImage;
            this.windowsFormsHost1.Child = chartViewer1;
        }
    }
}

I presume that we are not yet able to define the WinChartViewer directly in Window1.xaml
Do you have any comments/observations about the above?

Regards,

Julian

  Re: ChartDirector .NET control under WPF WindowsFormsHost
Posted by Peter Kwan on Feb-23-2011 10:21
Hi Julian,

I have not tried XAML myself, but I think it should work.

Note the WinChartViewer is not in the System.Windows.Forms namespace. Like everything in ChartDirector, it is in the ChartDirector namespace.

You may try:

xmlns:cd="clr-namespace:ChartDirector;assembly=netchartdir"

Then in XAML, you may try:

<WindowsFormsHost>
    <cd:WinChartViewer x:Name="xxx"/>
</WindowsFormsHost>

(I have not tried the above myself. I just infer the above from Microsoft documentation. You may need to modify it to make it work.)

Regards
Peter Kwan

  Re: ChartDirector .NET control under WPF WindowsFormsHost
Posted by Flemming Clausen on Feb-24-2011 21:46
Hi Julian,

I've managed to implement Chartdiretor in a Silverlight application (with limited funtions, I'll admit; i.e. no zooming e.a.) by using an image in a usercontrol.
Bindable from XAML to ViewModel.
maybe I have a few trick you can use.
Your welcome to send PM to fbc at systemate dot dk, if you'll like some inputs.
Regards
Flemming