Highlight on Mouse over

2 posts, 0 answers
  1. Warren
    Warren avatar
    4 posts
    Member since:
    Mar 2014

    Posted 12 Mar 2014 Link to this post

    I would like to highlight items in my charts when a user moves the mouse over them. For example, placing a border around a bar on a bar series or changing the color of a data point on a line series. When the user moves the mouse off of the item then it would return to it's normal appearance. Does anyone know how I can achieve this?
  2. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 17 Mar 2014 Link to this post

    Hi Warren,

    I think the Selection demo from our UI for WPF demos will be helpful for your scenario. You can find it under the RadChartView --> Selection section. 

    Basically you can set a PointTemplate on your series and then you can handle the MouseLeave and MouseEnter events on the UIElement placed in the template.
    <telerik:BarSeries ItemsSource="{Binding Items}"
                            ValueBinding="Value"
                            CategoryBinding="Category">
        <telerik:BarSeries.PointTemplate>
            <DataTemplate>
                <Border Background="LightCoral"
                        MouseEnter="Border_MouseEnter"
                        MouseLeave="Border_MouseLeave"/>
            </DataTemplate>
        </telerik:BarSeries.PointTemplate>
    </telerik:BarSeries>
    Here are the handlers:
    private void Border_MouseEnter(object sender, MouseEventArgs e)
    {
        Border border = sender as Border;
        border.BorderBrush = Brushes.LightSeaGreen;
        border.BorderThickness = new Thickness(5);
    }
     
    private void Border_MouseLeave(object sender, MouseEventArgs e)
    {
        Border border = sender as Border;
        border.BorderBrush = null;
        border.BorderThickness = new Thickness(0);
    }

    In addition I prepared a sample project which demonstrates this approach.

    Please let me know if this fits well in your scenario.

    Regards,
    Martin
    Telerik
     

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top