Page 1 of 1

Chart presentation in XAML with ContentPresenter

Posted: Wed Jul 13, 2011 12:25 pm
by 15659134
I need to add a collection of charts to a userinterface in wpf or silverlight
my code is like the following example:

C#:
ObservableCollection<TChart> ChartsCollection = new ObservableCollection<TChart>();

XAML:
<ListBox ItemsSource="{Binding ChartsCollection}">
</ListBox>

As the TChart object is derived from Control, why is the ListBox control not showing the chart objects?
When i change the heigt of the TChart object to 100 or 200, this change is visible in the ListBoxItems,
Which means the ItemsSource binding can find the TChart object, but cannot "render" the charts.

Am I missing something, or is this not possible in WPF?

Re: Chart presentation in XAML with ContentPresenter

Posted: Thu Jul 14, 2011 12:43 pm
by 10050769
Hello wdl,

Can you try to send us a simple project, so we can reproduce exactly your problem here and can try to help you to find a good solution?


Thanks,

Re: Chart presentation in XAML with ContentPresenter

Posted: Mon Aug 01, 2011 7:40 am
by 15659134
Yes, i will create a sample project this week, just returned from holiday.

Re: Chart presentation in XAML with ContentPresenter

Posted: Mon Aug 01, 2011 9:55 am
by 10050769
Hello wdl,

Thank you,we will wait your project :).

Thanks,

Re: Chart presentation in XAML with ContentPresenter

Posted: Mon Aug 01, 2011 11:53 am
by 15659134
Here is a sample project for what I want to achieve, using the MVVM pattern

MainView.xaml contains a listbox.
the datacontext of the MainView is set to the MainVM class.
the itemssource of the listbox is bound to the ChartsCollection property of MainVM.

I expected the lisbox to show the chartobjects from the Chartscollection.

The behaviour in this sample project is not what I expected, but this sample project should give an
idea of my goal.

Hope you can help me,

best regards

Re: Chart presentation in XAML with ContentPresenter

Posted: Wed Aug 03, 2011 2:49 pm
by 10050769
Hello wdl,

We are doing test with your project and we try to give you an answer asap with it.

Thanks,

Re: Chart presentation in XAML with ContentPresenter

Posted: Mon Aug 08, 2011 5:34 am
by 15659134
Hello Sandra,

Can you give me an update about the status of this topic?

Re: Chart presentation in XAML with ContentPresenter

Posted: Mon Aug 08, 2011 3:43 pm
by 10050769
Hello wdl,

We are working in it, we try to provide you and answer asap.

Thanks,

Re: Chart presentation in XAML with ContentPresenter

Posted: Fri Aug 12, 2011 8:24 am
by 10050769
Hello wdl,

Sorry, for the delay. We have been investigating, and we inform you that there are controls as example, list box that doesn't have Height and Width until you doesn’t add any elements with determinate Height and Width. And also, we add a simple code where you can check it and at the same time, I think you can use it to achieve as you want.

Code: Select all

MainVM _vm = new MainVM();
        public MainView()
        {
            InitializeComponent();
            this.DataContext = _vm;
            this.Loaded += new RoutedEventHandler(MainView_Loaded)

        }
        void MainView_Loaded(object sender, RoutedEventArgs e)
        {
           foreach (object logicalChild in LogicalTreeHelper.GetChildren(this))
                if (logicalChild is System.Windows.Controls.DockPanel)
                {
                    System.Windows.Controls.DockPanel dockPanel = ((System.Windows.Controls.DockPanel)(logicalChild));

                    foreach (object dockChild in LogicalTreeHelper.GetChildren(dockPanel))
                    {
                        if (dockChild is System.Windows.Controls.ListBox)
                        {
                            System.Windows.Controls.ListBox listBox1 = (System.Windows.Controls.ListBox)dockChild;

                            foreach (Steema.TeeChart.WPF.TChart chart in listBox1.Items)
                            {
                                chart.Height = this.Height;
                                chart.Width = this.Width;                           
                             }
                        }
                    }
                }
        }

Thank you,

Re: Chart presentation in XAML with ContentPresenter

Posted: Mon Aug 15, 2011 11:39 am
by 15659134
Hi Sandra,

Thanks for the suggestion, but this is not exactly what i was looking for.
I tested you solution and the charts were presented correctly instead of chart.width, but that can be another xaml setting.
The chart width and heigt are still static.

This solution will not work in Silverlight, because Silverlight has no LogicalTreeHelper.

Last week I created another workaround which works better for me.
see http://www.teechart.net/support/viewtop ... 47&start=0 were i reported the bug in the silverlight dll.
in this solution I add datagrid rows dynamicly to a named Grid element. this solution works better for me and the charts are resized automatically to the row's width and heigt.

I still haven't figured out a way to add charts by using the MVVM pattern, but the workaround I use now works for me.

best regards

Re: Chart presentation in XAML with ContentPresenter

Posted: Tue Aug 16, 2011 12:34 pm
by 10050769
Hello wdl,

Thanks for your information. I am glad that you can find a solution for your problem.

Thanks,