Show Tooltips on Point, Not Slope

5 posts, 0 answers
  1. Schley
    Schley avatar
    7 posts
    Member since:
    Jan 2009

    Posted 01 Feb 2012 Link to this post

    Is it possible to show a Tooltip for a data series only on the plotted points and not on the slope? I do not want the "closest" point's tooltip to be shown when the mouse hovers on the slope.
  2. Evgenia
    Admin
    Evgenia avatar
    1407 posts

    Posted 06 Feb 2012 Link to this post

    Hi Schley,

    You can remove the tooltip for the line and make it visible for the PointMarks by retemplating the style for the line:
    <UserControl.Resources>
        <Style x:Key="MyLineStyle"
               TargetType="telerik:Line">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="telerik:Line">
                        <Canvas x:Name="PART_MainContainer">
                            <telerik:PointMark x:Name="PART_PointMark"
                                               Canvas.Top="{TemplateBinding StartPointY}"
                                               PointMarkCanvasLeft="{TemplateBinding PointMarkCanvasLeft}"
                                               PointMarkCanvasTop="{TemplateBinding PointMarkCanvasTop}"
                                               Visibility="{TemplateBinding PointMarkVisibility}"
                                               ShapeStyle="{TemplateBinding PointMarkShapeStyle}"
                                               Style="{TemplateBinding PointMarkItemStyle}" />
                        </Canvas>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    Here's how to apply the Style to the Line Series:
    RadChart.DefaultSeriesDefinition = new LineSeriesDefinition()
    {
        ItemStyle = this.Resources["MyLineStyle"] as Style,
        ShowItemToolTips = true
    };

    Kind regards,
    Evgenia
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Schley
    Schley avatar
    7 posts
    Member since:
    Jan 2009

    Posted 06 Feb 2012 Link to this post

    Is there a way to define the resource in code? I'm using the WPF controls inside an ElementHost and loading resources is a bit of a pain. Thanks!
  5. Schley
    Schley avatar
    7 posts
    Member since:
    Jan 2009

    Posted 06 Feb 2012 Link to this post

    So here is what I'm trying to do. I've put the above XML into a text file and included it as an embedded resource called "NoTooltipsLineStyle":

    <UserControl.Resources>
        <Style x:Key="NoTooltipLineStyle"
               TargetType="telerik:Line">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="telerik:Line">
                        <Canvas x:Name="PART_MainContainer">
                            <telerik:PointMark x:Name="PART_PointMark"
                                                Canvas.Top="{TemplateBinding StartPointY}"
                                                PointMarkCanvasLeft="{TemplateBinding PointMarkCanvasLeft}"
                                                PointMarkCanvasTop="{TemplateBinding PointMarkCanvasTop}"
                                                Visibility="{TemplateBinding PointMarkVisibility}"
                                                ShapeStyle="{TemplateBinding PointMarkShapeStyle}"
                                                Style="{TemplateBinding PointMarkItemStyle}" />
                        </Canvas>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    Next I'm merging said resource file with the WPF resource dictionary:

    static PerfChartControl()
           {
               var wpfApp = WpfApplication.Current;
               
               var resDic = new ResourceDictionary
               {
                   {
                       @"NoTooltipLineStyle",
                       Properties.Resources.NoTooltipLineStyle
                       },
               };
     
               wpfApp.Resources.MergedDictionaries.Add(resDic);
               Log.Debug(@"merged resource dictionary with new xaml application");
           }

    Then I'm setting the line style:

    this.perfChartControl.DefaultSeriesDefinition =
                    new LineSeriesDefinition
                    {ItemStyle = Resources[@"NoTooltipLineStyle"] as Style,};

    All of this code compiles and runs fine, but the desired result is not occurring. For what it is worth I have also removed the UserControl.Resources element from the text I merge so that the Style element is the root node, but this has no effect.
  6. Evgenia
    Admin
    Evgenia avatar
    1407 posts

    Posted 09 Feb 2012 Link to this post

    Hi Schley,

    Why don't you just point your UserControls to the ResourceDictionary object. Here's what I mean:

    private void Form1_Load(object sender, EventArgs e)
    {
          UserControl1 uc1 = new UserControl1();
          this.elementHost1.Controls.Add(uc1);
     
          uc1.Resources = resDictionary;
    }
     
    More information on this approach can be found here.

    All the best,
    Evgenia
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top
UI for WPF is Visual Studio 2017 Ready