Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
375
Tooltip Background
posted

Hello!

How can I set the background of the tooltip that appears for the chart data points?

Currently I have the following:

StackPanel sp = new StackPanel();
TextBlock tbl = new TextBlock();
tbl.Foreground = new SolidColorBrush( Colors.White ); 
sp.Background = new SolidColorBrush( Colors.Blue ); 
tbl.SetBinding( TextBlock.TextProperty, new Binding( "Item.ToolTip" ) ); 
sp.Children.Add( tbl ); 

...

xmSeries.ToolTip = sp;

Now what this yields is a white box with a marker and a smaller box with blue background and white font with the tooltip text. Is there a way to make it so that the whole tooltip box has the needed background? I guess I need to redefine some DataTemplate in my app and assign it to xmSeries.ToolTip?

  • 30692
    Suggested Answer
    Offline posted

    Hi,

    You should update the TooltipStyle property on the chart. This is what introduces the default border and legend badge to the tooltip. To remove these, override the style with one of your own choosing.

    For reference, here is the default tooltip style that is applied:

     

    <Style x:Key="ToolTipStyle" TargetType="ContentControl">
            <Setter Property="Background" Value="#FFF7F8FA"/>
            <Setter Property="Foreground" Value="#FF373737"/>
            <Setter Property="Padding" Value="7"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="BorderBrush" Value="{StaticResource GenericBorder}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ContentControl">
                        <Border CornerRadius="4" BorderThickness="{TemplateBinding BorderThickness}" Background="#FFFFFFFF" BorderBrush="{TemplateBinding BorderBrush}">
                            <shared:SafeSetters.Setters>
                                <shared:SafeSetterCollection>
                                    <shared:SafeSetter PropertyName="Effect">
                                        <shared:SafeSetter.ValueAsXamlString>
                                            <DropShadowEffect xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Opacity="0.4"/>
                                        </shared:SafeSetter.ValueAsXamlString>
                                    </shared:SafeSetter>
                                </shared:SafeSetterCollection>
                            </shared:SafeSetters.Setters>
                            <Border BorderBrush="#FFFFFFFF" BorderThickness="1" CornerRadius="4" Background="{TemplateBinding Background}" >
                                <StackPanel Orientation="Horizontal">
                                    <ContentPresenter Content="{Binding}" ContentTemplate="{Binding Series.LegendItemBadgeTemplate}" />
                                    <ContentPresenter Margin="{TemplateBinding Padding}" Content="{TemplateBinding Content}"/>
                                </StackPanel>
                            </Border>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    


    Hope this helps!
    -Graham