Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > Chart > Show Tooltips on Point, Not Slope

Not answered Show Tooltips on Point, Not Slope

Feed from this thread
  • Schley avatar

    Posted on Feb 1, 2012 (permalink)

    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.

    Reply

  • Evgenia Evgenia admin's avatar

    Posted on Feb 6, 2012 (permalink)

    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 >>

    Reply

  • Schley avatar

    Posted on Feb 6, 2012 (permalink)

    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!

    Reply

  • Schley avatar

    Posted on Feb 6, 2012 (permalink)

    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.

    Reply

  • Evgenia Evgenia admin's avatar

    Posted on Feb 9, 2012 (permalink)

    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 >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > Chart > Show Tooltips on Point, Not Slope
Related resources for "Show Tooltips on Point, Not Slope"

WPF Chart Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]