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

Custom label, changes when redrawn

1 Answer 91 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 23 Jul 2013, 08:37 AM

hi

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">
        <Setter.Value>
            <ControlTemplate TargetType="telerikCharting:AxisLabel2D">
                <Border Background="{TemplateBinding Background}">
                    <Border.DataContext>
                        <MultiBinding Converter="{StaticResource GetTextConverter}">
                            <MultiBinding.Bindings>
                                <Binding Path="DataContext" ElementName="_GD"/>
                                <Binding Path="CurrentIndex"/>
                            </MultiBinding.Bindings>
                        </MultiBinding>
                    </Border.DataContext>
                    <TextBlock Style="{TemplateBinding ItemLabelStyle}" Text="{Binding .}">
                        <TextBlock.LayoutTransform>
                            <RotateTransform x:Name="PART_RotateTransform" />
                        </TextBlock.LayoutTransform>
                    </TextBlock>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

1 Answer, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 26 Jul 2013, 08:04 AM
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.

Regards,
Evgenia
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 >>
Tags
Chart
Asked by
Martin
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Share this question
or