Okay. I have a Timeline where I want to read the number and names of the series from a database, then generate the points in each series to be displayed. I can't get any sort of binding to work for the Series.
I also want to change the shape of the points on the timeline.
Are these achievable?
After posting this, I've searched more and found this article: https://es.infragistics.com/community/forums/t/105114.aspx.
This seems promising, but I'm using a XamTimeline, not a XamDataChart. Still, I can see that the approach might be applicable.
What I can't see, however, is how to "connect the dots" between the solution and the problem, so that I can make modifications that I'll need for my solution.
The solution looks like an "attached property." I'm guessing that the attached property replaces (overrides?) some of the properties of the XamDataChart (I can see that the attached property provides "Series.").
If this approach is a "normal" method of doing things in WPF, can you suggest a resource for me to learn the approach? I've only been working in WPF for six months.
Hi Joe,
Just to make sure I understand what you are trying to do, you want to essentially be able to bind to the XamTimeline's Series collection? The use case being that your database has an unknown number of series so once you grab that data you want to bind it to the XamTimeline and have the timeline automatically create the subsequent series and bind up the data. Do I have that right?
If so, and you don't care about MVVM (you should care about MVVM :p), you can dynamically create series in code behind and add them to the XamTimeline.Series collection. I don't recommend this though. Unfortunately the Series property on the XamTimeline isn't meant to be bound to so the MVVM way of doing this would be to go with a route similar to the one you described, either with an attached property or a Behavior<T>.
Either approach will work but I tend to lean towards using Behavior<T> when I can as I think it's a bit cleaner than attached properties. If you need to attach custom behaviors to a control through a Style then attached properties are the only option. Doing it through a style is useful when you want the same behavior applied to multiple controls.
I have attached a sample project which demonstrates both approaches. The code for both attached properties and Behavior<T> is pretty similar. In the sample it shows how you can bind a collection of "series" items from your view model and specify what properties the real XamTimeline series should be pulling its Title, DataSource and DataMapping properties from in your data.
Let me know if you have any questions.
I want to add a note that this sample is really just a starting point. All it does is load data into the timeline. If you add more data or remove data it won't respond as that still needs to be implemented. In the behavior code you will see where I handle the CollectionChanged event but the handler is empty. In that handler would be where you add and remove the timeline series depending on whether items were added or removed from your view model data.
From what I can see of the LegendItem, there is nothing provided to it that indicates which series it is associated with aside from the title of the series. We're creating these LegendItems internally and assigning their Content property the title of the NumericTimeSeries or DateTimeSeries as a string. Unfortunately that's all it has to work with.
If your series titles are guaranteed to be unique you could use that as an identifier for your series data and find it that way. Otherwise you may be better off disabling the timeline's legend and providing your own UI for it if the default legend doesn't have enough functionality. You'll still have access to all the series Titles in the XamTimeline's Series collection or you could make it such that the legend binds directly to your series data and uses the information from there instead.
I recommend submitting a new product idea for updating the XamTimeline legend functionality to include some information about what series each LegendItem is associated with to make it a bit easier to retemplate. You can do this here: http://ideas.infragistics.com.
I've gotten the images on my timeline. I want to place the image in the legend, too. I'm templating LegendItem, but can't figure out how to get the image from the SeriesData I've used to populate the series collection.
How do I select the particular instance from the collection that "this LegendItem" represents?
I marked your first answer as the solution. The others have helped clear up confusion that I had on different issues.
I have my points on the timeline, they are using my bitmaps, and are positioned correctly (well, mostly :)).
Unless you object, I'm going to start a new post with the other things that I've yet to resolve (or, maybe I should say, you've yet to resolve, since I haven't done much without your help).
Again, Thanks!
Somewhere we got our wires crossed. I'm not having any issues with event descriptions disappearing. My problem is with what I would call the positioning of the event point. If my event has a time of 49.5 and a duration of 1, the "bubble" is shown on the timeline starting at 50, not centered on 50.
I'll try the Parent on the event point's class.
The timeline does hide certain event descriptions depending on the space available so nothing collides, so it's possible that there isn't enough space in your timeline to display all of them? In my sample, I modified it so that it would alternate series between TopOrLeft and BottomOrRight and I do see some series in both locations (given enough space) so I don't think there's anything special needed there. All I did was set the Position property, nothing else. Can you modify my sample to reproduce your issue and send it back to me so I can take a look at what's going on?
For the EventPoint style, the EventPoint's DataContext is actually your data point so if your image URL is there you can bind directly to it. If the URL is in your own series object contained in the view model then you'll need to access it a different way. You could add a property to your data point called "Parent" which references back to the series object the data point belongs to. Then you could access properties of the series object in the EventPoint.
The TimelineSeriesBinding class / attached properties don't associate the view model series object with the XamTimeline series object and even if it did you wouldn't be able to access the XamTimeline series through the EventPoint as there's no reference to it there. You'd have to bind up the visual tree to the XamTimeline and then access its Series collection. From there you'd have to iterate through the DataSource for each series and see if the EventPoint's DataContext was contained inside in order to determine which XamTimeline series the data point belonged to. This would only work if you had associated the XamTimeline series with the view model one. I think it would be simpler just to add a new property to the data point that references the parent series so you can access the image with a simple binding like this:
(Since the EventPoint's DataContext is already the data point, no binding Source is required)<Image Source="{Binding Path=Parent.EventPointImage}"/>