How to Style Label

4 posts, 0 answers
  1. Keaire
    Keaire avatar
    15 posts
    Member since:
    Nov 2013

    Posted 31 Mar 2014 Link to this post

    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?
  2. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 03 Apr 2014 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Christian
    Christian avatar
    1 posts
    Member since:
    Nov 2015

    Posted 17 Feb in reply to Evgenia Link to this post

    Hy Evgenia,

     

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

    Which refernce do i need to access DataBarShape?

    Thx in advance

  5. Evgenia
    Admin
    Evgenia avatar
    1406 posts

    Posted 22 Feb Link to this post

    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
Back to Top