Chart presentation in XAML with ContentPresenter

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
wdl
Newbie
Newbie
Posts: 12
Joined: Wed Apr 20, 2011 12:00 am

Chart presentation in XAML with ContentPresenter

Post by wdl » Wed Jul 13, 2011 12:25 pm

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?

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Chart presentation in XAML with ContentPresenter

Post by Sandra » Thu Jul 14, 2011 12:43 pm

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,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

wdl
Newbie
Newbie
Posts: 12
Joined: Wed Apr 20, 2011 12:00 am

Re: Chart presentation in XAML with ContentPresenter

Post by wdl » Mon Aug 01, 2011 7:40 am

Yes, i will create a sample project this week, just returned from holiday.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Chart presentation in XAML with ContentPresenter

Post by Sandra » Mon Aug 01, 2011 9:55 am

Hello wdl,

Thank you,we will wait your project :).

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

wdl
Newbie
Newbie
Posts: 12
Joined: Wed Apr 20, 2011 12:00 am

Re: Chart presentation in XAML with ContentPresenter

Post by wdl » Mon Aug 01, 2011 11:53 am

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
Attachments
testApplication.rar
sample project
(43.42 KiB) Downloaded 444 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Chart presentation in XAML with ContentPresenter

Post by Sandra » Wed Aug 03, 2011 2:49 pm

Hello wdl,

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

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

wdl
Newbie
Newbie
Posts: 12
Joined: Wed Apr 20, 2011 12:00 am

Re: Chart presentation in XAML with ContentPresenter

Post by wdl » Mon Aug 08, 2011 5:34 am

Hello Sandra,

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

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Chart presentation in XAML with ContentPresenter

Post by Sandra » Mon Aug 08, 2011 3:43 pm

Hello wdl,

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

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Chart presentation in XAML with ContentPresenter

Post by Sandra » Fri Aug 12, 2011 8:24 am

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,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

wdl
Newbie
Newbie
Posts: 12
Joined: Wed Apr 20, 2011 12:00 am

Re: Chart presentation in XAML with ContentPresenter

Post by wdl » Mon Aug 15, 2011 11:39 am

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

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Chart presentation in XAML with ContentPresenter

Post by Sandra » Tue Aug 16, 2011 12:34 pm

Hello wdl,

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

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply