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

Can't change legendstyle at runtime

5 Answers 65 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Brendan
Top achievements
Rank 1
Brendan asked on 07 Apr 2011, 04:27 AM
If I have a chart style set and then change it at runtime with a different legendstyle, the property is ignored and the legend remains the same. However if I change the legend style directly it works (i.e. Chart.DefaultView.ChartLegend.Style). The same thing hapopens with legend items and other components. This is very annoying when trying to switch styles as I must cycle through every component and change it manually, rather than setting up a a single chart style.

5 Answers, 1 is accepted

Sort by
0
Sia
Telerik team
answered on 08 Apr 2011, 02:16 PM
Hello Brendan,

Can you please give us more information about what you need to style run-time in the legend and the legend items?

Thank you,
Sia
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Brendan
Top achievements
Rank 1
answered on 11 Apr 2011, 01:09 AM
At best I would like to change the control template for legend items, however if I could at least change the background and foreground it would be useful. I have a chart which I would like to export, however the styles used in my application do not suit, so before exporting i need to change the style and then back again.
0
Sia
Telerik team
answered on 13 Apr 2011, 04:24 PM
Hello Brendan,

Please review the attached code. There are two styles: CustomLegendItem1 with only two setters and CustomLegendItem2 with the whole template (without all Visual States). In my opinion the first one is what you need. Please try it and let me know how it goes.

Regards,
Sia
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Brendan
Top achievements
Rank 1
answered on 14 Apr 2011, 01:54 AM
I'm sorry but the example you gave is exactly my problem - rather than being able to change just the chart style, you had to cycle through each component and change each style them individually. I've modified your example to show what I am trying to do:

MainPage.xaml:
<UserControl.Resources>
        <!-- Chart styles 1 -->
        <Style x:Key="LegendItemStyle1" TargetType="telerikCharting:ChartLegendItem">
            <Setter Property="Foreground" Value="White" />
        </Style>
 
        <Style x:Key="ChartLegendStyle1" TargetType="telerikCharting:ChartLegend">
            <Setter Property="Background" Value="Black" />
            <Setter Property="LegendItemStyle" Value="{StaticResource LegendItemStyle1}" />
        </Style>
 
        <Style x:Name="RadChartStyle1" TargetType="telerik:RadChart">
            <Setter Property="Background" Value="Black" />
            <Setter Property="Foreground" Value="White" />
            <Setter Property="LegendStyle" Value="{StaticResource ChartLegendStyle1}" />
        </Style>
 
 
        <!-- Chart styles 2 -->
        <Style x:Key="LegendItemStyle2" TargetType="telerikCharting:ChartLegendItem">
            <Setter Property="Foreground" Value="Black" />
        </Style>
 
        <Style x:Key="ChartLegendStyle2" TargetType="telerikCharting:ChartLegend">
            <Setter Property="Background" Value="White" />
            <Setter Property="LegendItemStyle" Value="{StaticResource LegendItemStyle2}" />
        </Style>
 
        <Style x:Name="RadChartStyle2" TargetType="telerik:RadChart">
            <Setter Property="Background" Value="White" />
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="LegendStyle" Value="{StaticResource ChartLegendStyle2}" />
        </Style>
    </UserControl.Resources>
 
    <Grid x:Name="LayoutRoot">
        <telerik:RadChart x:Name="RadChart1" Style="{StaticResource RadChartStyle1}" />
        <Button Content="Click" Width="100" Height="30" Click="Button_Click" />
    </Grid>

MainPage.cs:
public partial class MainPage : UserControl
    {
        public bool flag = false;
 
        public MainPage()
        {
            InitializeComponent();
 
            List<Company> sampleData = new List<Company>();
            sampleData.Add(new Company("AAA", 3000));
            sampleData.Add(new Company("BBB", 3005));
 
            SeriesMapping seriesMapping = new SeriesMapping();
            seriesMapping.ItemMappings.Add(new ItemMapping("Price", DataPointMember.YValue));
            seriesMapping.SeriesDefinition = new AreaSeriesDefinition(){ };
    
            RadChart1.SeriesMappings.Add(seriesMapping);
 
            RadChart1.ItemsSource = sampleData;
        }
 
        public class Company
        {
            public string Name { get; set; }
            public double Price { get; set; }
 
            public Company(string name, double price)
            {
                Name = name;
                Price = price;
            }
        }
           
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            RadChart1.Style = Resources[flag ? "RadChartStyle1" : "RadChartStyle2"] as Style;
            flag = !flag;
        }
    }

When clicking the button the legend and legend item styles do not change - so the chart uses style 2, whereas the legend still uses style 1.
0
Sia
Telerik team
answered on 19 Apr 2011, 01:49 PM
Hello Brendan,

I have logged this issue in our Public Issues Tracking System. Please use the suggested approach instead and find your telerik points updated.

Regards,
Sia
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
Chart
Asked by
Brendan
Top achievements
Rank 1
Answers by
Sia
Telerik team
Brendan
Top achievements
Rank 1
Share this question
or