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

How to Style Label

3 Answers 278 Views
DataBar
This is a migrated thread and some comments may be shown as answers.
Keaire
Top achievements
Rank 1
Keaire asked on 31 Mar 2014, 04:39 PM
For some reason, I'm unable to apply a LabelText attribute on the RadDataBar. Its ControlTemplate contains a TextBlock which uses TemplateBinding to bind to the AppliedLabelMargin and LabelText properties, but they're not available.

What gives?

3 Answers, 1 is accepted

Sort by
0
Accepted
Evgenia
Telerik team
answered on 03 Apr 2014, 04:05 PM
Hi,

Indeed most of the properties in RadDatabar such as AppliedLabelMargin and LabelText have only getters and that's why you can't access them as direct properties of the DataBar. However you can retemplate the databar control and bind to custom business object properties so that custom text gets visualized. For example:

<UserControl.Resources>
        <Style TargetType="telerik:RadDataBar">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="telerik:RadDataBar">
                        <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}" >
                            <Grid>
                                <dataBars:DataBarShape Fill="{TemplateBinding AppliedBarBrush}"
                                                    Style="{TemplateBinding BarStyle}"
                                                    Stroke="{TemplateBinding AppliedBarBorderBrush}"
                                                    StrokeThickness="{TemplateBinding BarBorderThickness}"
                                                    HeightPercent="{TemplateBinding BarHeightPercent}"
                                                    RightPercent="{TemplateBinding BarRightPercent}"
                                                    LeftPercent="{TemplateBinding BarLeftPercent}"
                                                    OutOfRangeRule="{TemplateBinding AppliedOutOfRangeRule}" />
                                <ContentPresenter ContentTemplate="{TemplateBinding AppliedOutOfRangeTemplate}" />
                                <Rectangle Margin="{TemplateBinding AppliedAxisMargin}"
                                         Fill="{TemplateBinding AxisStroke}"
                                         Style="{TemplateBinding AxisStyle}"
                                         Visibility="{TemplateBinding AppliedAxisVisibility}"
                                         HorizontalAlignment="Left"/>
                                <TextBlock Text="{Binding Name}"
                                       Style="{TemplateBinding LabelStyle}"
                                       Visibility="{TemplateBinding LabelVisibility}"
                                       Margin="{TemplateBinding AppliedLabelMargin}"
                                       VerticalAlignment="Center" />
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
 
    <Grid x:Name="LayoutRoot" Background="White">
        <telerik:RadDataBar Height="20" Value="{Binding Val}" OriginValue="20" BorderBrush="Gray" BorderThickness="1" Margin="2" ValueBrush="RoyalBlue" />
    </Grid>


And the business objects class:

public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            this.DataContext = new Item() { Val = 40, Name = "My Product" };
        }
 
        public class Item
        {
            public double Val { get; set; }
            public string Name { get; set; }
        }
    }


Regards,
Evgenia
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Christian
Top achievements
Rank 1
answered on 18 Feb 2016, 02:55 AM

Hy Evgenia,

 

im wondering where "dataBars:DataBarShape" is refernced to?

Which refernce do i need to access DataBarShape?

Thx in advance

0
Evgenia
Telerik team
answered on 22 Feb 2016, 09:38 AM
Hello Christian,

You can easily see what is the exact namespace mapping that xmlns:databars points to if you open the default control template as we defined it in our themes. For the purpose you might use one of the approaches described here.

I'm pasting it here for your ease:

xmlns:dataBars="clr-namespace:Telerik.Windows.Controls.DataBars;assembly=Telerik.Windows.Controls.DataVisualization"


Regards,
Evgenia
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DataBar
Asked by
Keaire
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Christian
Top achievements
Rank 1
Share this question
or