Pre loader

FAQ: How to Show/Hide Axis Title without changing the axis text

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

Answered Closed

On priority support tickets, a user just asked us how to show and hide the AxisTitle TextBlock without changing the AxisTitle.Text to string.Empty.

The solution uses attached properties and a small custom style, so we thought we’d post it below

  • You must to post comments
Best Answer

The solution is to use the Axis TitleStyle to control visibillity of the axis title text block via an attached property.

Start out by creating this code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace WpfApplication2
    // Define attahced property
    public class AxisExtensions
        public static readonly DependencyProperty DrawAxisTitleProperty = DependencyProperty.RegisterAttached(
            "DrawAxisTitle", typeof(bool), typeof(AxisExtensions), new PropertyMetadata(true));

        public static void SetDrawAxisTitle(DependencyObject element, bool value)
            element.SetValue(DrawAxisTitleProperty, value);

        public static bool GetDrawAxisTitle(DependencyObject element)
            return (bool)element.GetValue(DrawAxisTitleProperty);


<Window x:Class="WpfApplication2.MainWindow"
        Title="MainWindow" Height="350" Width="525">

        <BooleanToVisibilityConverter x:Key="b2v"></BooleanToVisibilityConverter>
        <Style x:Key="BottomAxisTitleStyle" TargetType="s:AxisTitle">
            <Setter Property="ContentTemplate">
                        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding}"
                                   Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=s:DateTimeAxis}, Path=(common:AxisExtensions.DrawAxisTitle), Converter={StaticResource b2v}}"/>
                <s:DateTimeAxis AxisTitle="Hello World!" TitleStyle="{StaticResource BottomAxisTitleStyle}" common:AxisExtensions.DrawAxisTitle="True"/>

That’s it!

enter image description here

The attached property AxisExtensions adds a boolean property to the Axis itself. Next, the declared Axis TitleStyle has a TextBlock with Text-value bound to its data context (in this case the axis title string), and Visibility set to a RelativeSource binding up to the AxisExtensions.DrawAxisTitle attached property.

For more information on axis part templating, please see our article titled Styling Axis Labels, Axis Titles, Rotating Axis Labels

  • You must to post comments
Showing 1 result