Can't change legendstyle at runtime

6 posts, 0 answers
  1. Brendan
    Brendan avatar
    34 posts
    Member since:
    Oct 2010

    Posted 06 Apr 2011 Link to this post

    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.
  2. Sia
    Admin
    Sia avatar
    765 posts

    Posted 08 Apr 2011 Link to this post

    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
  3. Brendan
    Brendan avatar
    34 posts
    Member since:
    Oct 2010

    Posted 10 Apr 2011 Link to this post

    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.
  4. Sia
    Admin
    Sia avatar
    765 posts

    Posted 13 Apr 2011 Link to this post

    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
  5. Brendan
    Brendan avatar
    34 posts
    Member since:
    Oct 2010

    Posted 13 Apr 2011 Link to this post

    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.
  6. Sia
    Admin
    Sia avatar
    765 posts

    Posted 19 Apr 2011 Link to this post

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