Label format for Zero (0)

3 posts, 1 answers
  1. Tauqir
    Tauqir avatar
    10 posts
    Member since:
    Jul 2013

    Posted 16 Jan 2014 Link to this post

    I am using the following code to format the scale. 

    <
    telerik:RadialScale Min="0" Max="55000" Multiplier=".001" IsInteractive="True" MajorTickStep="5000" LabelLocation="OverInside" FontSize="11" LabelOffset="-25" LabelRotationMode="None" StartAngle="160" SweepAngle="220" LabelFormat="{}{0:F0}k">

    Using a multiplier and a label format, I'm displaying values such as 5K, 10K, etc. instead of 5000, 10000, etc.
    However, my first value shows up as '0K', while I would like just '0' (zero) to be shown.
    How  can I achieve this? Thanks.
  2. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 20 Jan 2014 Link to this post

    Hello Tauqir,

    You can specify the custom data template for labels via the RadialScale.LabelTemplate property. And then you can bind the text of each label in the template using a custom converter which will change the text for the 'zero' label.

    The sample code is below.

    <Window x:Class="CustomFirstLabel.MainWindow"
            xmlns:local="clr-namespace:CustomFirstLabel"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <local:CustomLabelConverter x:Key="CustomLabelConverter" />
        </Window.Resources>
        <Grid>
            <telerik:RadialScale Min="0" Max="55000" Multiplier=".001" IsInteractive="True" MajorTickStep="5000"
                                 LabelLocation="OverInside" FontSize="11" LabelOffset="-25" LabelRotationMode="None"
                                 StartAngle="160" SweepAngle="220" LabelFormat="{}{0:F0}k">
                <telerik:RadialScale.LabelTemplate>
                    <DataTemplate>
                        <TextBlock HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   FontFamily="{Binding FontFamily}"
                                   FontSize="{Binding FontSize}"
                                   FontStretch="{Binding FontStretch}"
                                   FontStyle="{Binding FontStyle}"
                                   FontWeight="{Binding FontWeight}"
                                   Foreground="{Binding Foreground}"
                                   Text="{Binding Path=FormattedValue, Converter={StaticResource CustomLabelConverter}}" />
                    </DataTemplate>
                </telerik:RadialScale.LabelTemplate>
            </telerik:RadialScale>
        </Grid>
    </Window>
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Data;
     
    namespace CustomFirstLabel
    {
        public class CustomLabelConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                string formattedValue = (string)value;
                if (formattedValue.StartsWith("0"))
                {
                    return "0";
                }
     
                return value;
            }
     
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }
    }

    Give it a try and let me know if it helps.

    Regards,
    Andrey Murzov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.

    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Tauqir
    Tauqir avatar
    10 posts
    Member since:
    Jul 2013

    Posted 19 Mar 2014 in reply to Andrey Link to this post

    Thanks, that worked perfectly.
Back to Top