This is a migrated thread and some comments may be shown as answers.

Label format for Zero (0)

2 Answers 101 Views
Gauges
This is a migrated thread and some comments may be shown as answers.
Tauqir
Top achievements
Rank 1
Tauqir asked on 16 Jan 2014, 10:12 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Andrey
Telerik team
answered on 20 Jan 2014, 04:13 PM
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 >>
0
Tauqir
Top achievements
Rank 1
answered on 19 Mar 2014, 03:07 PM
Thanks, that worked perfectly.
Tags
Gauges
Asked by
Tauqir
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Tauqir
Top achievements
Rank 1
Share this question
or