I'd like to add a new event to the timeline based on the location of a mouse click. My question is how to tell where on the timeline the user clicked?
Hi,
You can try using the following code:
private void Timeline1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Point pt = e.GetPosition(this.Timeline1);
double value = this.Timeline1.Axis.GetPixelValue(pt.X);
NumericTimeEntry entry = new NumericTimeEntry() { Time = value, Title = "New Entry" };
NumericTimeSeries series = this.Timeline1.Series[0] as NumericTimeSeries;
series.Entries.Add(entry);
}
In the case you are working with DateTime values you can convert the value to DateTime with:
DateTime time = new DateTime((long)value);
Hello,
Do you have any other questions on this matter?
Valerie
Solved.
Forgot to mention that I am using XamDataChart.
How to catch the mouse down event on Axes ? When I click the axes label or around, it never break at MouseDown event method (where I set break point). Only breaks when I click on the chart itself.
Sorry for taking so long to reply. This seems to work.
I changed the code slightly to work on mouse down on the Axis instead of the timeline. That way it ignores clicks on the zoom control. I think I will also have to check for clicks on or near the thumb control so the user can move that around without creating a new entry at that point.
Thanks for the help, I really appreciate your customer service!