This is a migrated thread and some comments may be shown as answers.

Annotation Click Event

1 Answer 131 Views
TimeLine
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 05 Jun 2015, 08:38 AM

I have an annotation on my timeline which I want to move up/down in time.

I know I can just change the annotations Date to do this, but How can I get the user to interact with the annotation.

It does not trigger the SelectionChanged event (cos it's not a item).

Is there a way to identify it the mouse down, move and up events, so I can calculate it's new Date value there??

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 09 Jun 2015, 11:23 AM
Hello Jason,

In order to achieve your requirement you can subscribe for the MouseLeftButtonDown/Up and MouseMove events of the timeline and inside the MouseMove event handler set the new date of the annotation. You can calculate the date under the mouse using the timeline's ConvertPointToDateTime() method. Here is an example in code for this approach:
this.xAnnotation.MouseLeftButtonDown += xAnnotation_MouseLeftButtonDown;
this.xRadTimeline.MouseLeftButtonUp += xRadTimeline_MouseLeftButtonUp;
this.xRadTimeline.MouseMove += xRadTimeline_MouseMove;
 
.....
 
void xAnnotation_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    this.isDragging = true;
}
 
void xRadTimeline_MouseMove(object sender, MouseEventArgs e)
{
    if (this.isDragging)
    {               
        var point = e.GetPosition(this.xRadTimeline);
        var dateTime = this.xRadTimeline.ConvertPointToDateTime(point);
        this.xAnnotation.StartDate = dateTime;
    }
}
 
void xRadTimeline_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{           
    this.isDragging = false;
}

<telerik:RadTimeline.Annotations>
    <telerik:TimelineAnnotation x:Name="xAnnotation"                                           
                                IsHitTestVisible="True">
        <telerik:TimelineAnnotation.ContentTemplate>
            <DataTemplate>
                <Border Background="#007ACC" Width="10" />
            </DataTemplate>
        </telerik:TimelineAnnotation.ContentTemplate>
    </telerik:TimelineAnnotation>
</telerik:RadTimeline.Annotations>
Note that I am setting the IsHitTestVisible of the annotation to true. This is necessary because its default value is set to False which means that the annotation won't participate in the user interaction and its mouse events won't be fired.

You can also take a look at the attached project which demonstrates this approach. Please give it a try and let me know if it helps.

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
TimeLine
Asked by
Jason
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or