XamDataChart with unknown number of series - c#

I am using an Infragistics XamDataChart and want to bind a collection in my view model to the chart's Series property, since I don't know in advance how many line charts I will need to display.
From what I can gather from old posts in the Infragistics support forums, the Series property is read only and thus doesn't support binding directly. A solution is offered here but it seems like overkill for such a simple goal (maybe to me it just seems simple).
Has anyone here done any work with the Infragistics xamDataChart and MVVM? The ultimate goal is to be able to have a collection in my view model that contains a variable number of 'series' that I can just bind to the chart. Now I can probably do this if I just write some code behind for my xaml, access the DataContext (viewModel) and listen to the collection property, directly adding/removing series to the chart as necessary, but I was looking for a more MVVM way.
Thanks.

Since the Series collection of the XamDataChart is read-only, in order to be able to generate the Series dynamically,based on you VeiwModel, you should use helper class, similar to the approach that Graham Murray has suggested in the thead that you have referred. I have created a sample applicaiton, that show how you can create similar appraoch for binding the series of the XamDataChart to collection of your ViewModel. You can download the sample from here:
http://users.infragistics.com/Samples/SeriesBinder.zip
Sincerely,
Krasimir

Related

What's the difference between a stackpanel with datatemplates or a listview with listitems

I'm creating a WPF program that consumes rest api data. I want to implement lazyloading and infinite scroll on the data and programmatically create and add either custom data templates or listitems very similar to this design
I'm just confused as to which approach to take and what benefits/costs each provides
Easy choices:
Everyone uses MVVM so use MVVM.
Data Templating is a fundamental of wpf and building UI in code is not recommended - so use data templating.
You can dynamically add templates to resources by building xaml as strings. This is the MS recommended way to build any dynamic UI. Those strings can come from flat files, a database directly or a web service and you can build them by manipulating txt files or serialising controls.
A huge plus of this is you have the markup "right there". So when things go pear shaped you can paste into an experimental solution and see the errors light up in the xaml or see what the user is seeing.
If datatype associated templating doesn't suit for some reason then you could write a datatemplateselector and put your logic in there.
I'm not sure how you expect that to scroll exactly but I'd go with a listbox, some datatemplates associated with a type per view. Assuming the items can have different views - you just seem to have that "gilded" button or tag as an option.
Load your data into viewmodels with one per row.
.Add to an Observablecollection which is a public property in a viewmodel.
Bind that to the itemssource of a listbox.
They are then templated into UI.
A listbox has a scroller built in but you could re-template if you wanted to scroll using some other approach.
A StackPanel is a Panel that arranges child elements into a single line that can be oriented either horizontally or vertically.
A ListView is an ItemsControl that you can bind to an IEnumerable of objects and is used to present a collection of items.
What you should do is to create an ItemsControl with an ItemTemplate that corresponds to a scrollable item in the list. There is a basic example available here and you will find a lot more examples online.

Creating binding source vs just assigning a List<C> for combobox?

In the following link, the author shows how to create a binding source and add sorting function to a grid view. It should work similarly for combobox datasource. However does it have any benefit to do it for simpler controls like combobox or listbox? I can just assign a list of type List<AClass> and then assign the DisplayMember and Value for the controls.
http://aviadezra.blogspot.com/2008/06/binding-domain-objects-in-visual-studio.html
Even for data grid view, does it work well for complex situation like, for example, sorting on a grid view with paging? Looks the class PropertyComparerCollection in the example only works the loaded data.
The article is focused on binding complex business objects to the grid view. This has been a intensively debated subject since .Net Framework 2.0. If the properties of your bound type are no longer primitive, then you have to get your hands dirty to support sorting, filtering or searching.
There are plenty generic classes for this goal, but I would recommend this implementation, with a nice video demo here.
However, if you're not aiming at a data grid view, but rather at a combo box or list box, and wish not to modify the underlying store while sorting or filtering, you could still use a custom class derived from IBindingListView and BindingList(of T), like the one suggested above and manually call ApplySort or ApplyFilter. The implementation in the article linked in your post and the one I suggested use temporary copies of the original data source for sorting/filtering.
Furthermore, for paging instead of taking slices out of the original data source, you'd be taking slices out of the wrapped sortable view of that data source.

DataBinding to Charts

I am trying to create some charts for a C# .NET 4.0 Winforms application. I have begun with the pie-Chart. Is there a way to use databinding in order to keep the chart updated?
So far I have only managed to use the DataPoint.YValues property to change the chart's appearance.
The Series object has got a DataSource property, but I am not sure how to use this DataSource for the single points (which are inside a list, inside the series property).
I hope I could explain my question detailed enough.
PS: The charts are from the System.Forms.DataVisualization.Charting namespace.

How to dynamically update a listviewitem through code

I have a listview and would like to update the text of one of the columns for a specific listviewitem (row).
How would I go about doing this?
Hard to say without any context because there are so many ways you could populate your list!
The generic answer is you bind your list to a collection view which itself binds its source to your viewmodel (or you bind directly to your viewmodel if you don't need CollectionView features).
When you want to modify your list, you make sure you raise a modification notification on your property, and XAML binding will take care of updating everything.
It is really basic stuff on dependency property and binding, you should read more about this topic. MVVM-light is a very light framework that allows you to take care of all kinds of binding-related issues with a very clean and neat flavor. You will also find some very good self-explanatory webcasts from the author of the website about all those topics.

Silverlight 3 - Filtering an Observable Collection

Is there a way to filter/sort an observable collection and still keep the notifications?
I have looked around and I found CollectionViewSource which filters and sorts the collection as I require but when the an items property in which the filter relies changes at the source collection it does not refresh the filter.
Basically i require a view of the original collection that when a property of an item in the view changes it updates the source and when the source changes it updates the view. Is there any class that provides this functionality in silverlight 3?
Does ObservableCollection with TwoWay binding not work? Can you elaborate your example with some code to show the issue in more detail?
I would suggest using the Bindable.Linq library, it hasn't been updated for a while and there is a bug with the Union operator. But for linq style filters it works great.
heres a quick example, assuming this is in the codebehind of a silverlight user control with a listbox named people:
using Bindable.Linq;
...
ObservableCollection<Person> data = new ObserableCollection<Person>{.... fill in};
people.ItemsSource = data.AsBindable(Dispatcher).Where(p => p.FirstName.Equals("steve"));
data.add(new Person("steve"));
if you do this steve should show up on the list. I have found this library very useful and if you download the sample projects from codeplex it shows more advanced examples.
Hope this helps.
There are several other similar projects

Categories

Resources