Custom label, changes when redrawn

2 posts, 0 answers
  1. Martin
    Martin avatar
    3 posts
    Member since:
    Jul 2013

    Posted 23 Jul 2013 Link to this post


    i was given a solution to enable to re-template the AxisLabel2d controls which worked fine. See attached

    When i resize the window, the labels revert back to the defaulted state (timedate), initally it is fine.

    My converter does nothing but return a string. I restyle using the code below (as per the suggestion by you guys)

                ChartArea area = _CA;
                HorizontalAxisLabels2D axisLabelsContainer = area.FindChildByType<HorizontalAxisLabels2D>();
                var axisLabels = axisLabelsContainer.ChildrenOfType<AxisLabel2D>();
                System.Windows.Style style = _GD.Resources["CustomLabel"] as System.Windows.Style;
                foreach (var item in axisLabels)
                    item.Style = style;

        public class GetTextConverter : IValueConverter, IMultiValueConverter
            public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
                return "I Am HERE";
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
                return "I Am HERE";

            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException();}
            public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotImplementedException(); }


    <Style x:Key="CustomLabel" TargetType="telerikCharting:AxisLabel2D">
        <Setter Property="Template">
                <ControlTemplate TargetType="telerikCharting:AxisLabel2D">
                    <Border Background="{TemplateBinding Background}">
                            <MultiBinding Converter="{StaticResource GetTextConverter}">
                                    <Binding Path="DataContext" ElementName="_GD"/>
                                    <Binding Path="CurrentIndex"/>
                        <TextBlock Style="{TemplateBinding ItemLabelStyle}" Text="{Binding .}">
                                <RotateTransform x:Name="PART_RotateTransform" />

  2. Evgenia
    Evgenia avatar
    1437 posts

    Posted 26 Jul 2013 Link to this post

    Hello Martin,

     The approach you are using is correct however it is not clear from your code snippet on what event do you wire to set the item.Style.
    I prepared a sample to reproduce the unwanted behaviour with the labels, however everything is working as expected on my side. I attached it here for you to test as well. Some notes on the sample attached: I used the Framework implicit style mechanism that is applying the certain style to all elements of a certain type. Also I'm not using MultiBinding but you are free to modify the code per your requirement and I believe that everything will be working as desired.

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