LegendItem Text Color

4 posts, 1 answers
  1. Jeroen
    Jeroen avatar
    49 posts
    Member since:
    Feb 2012

    Posted 01 Jun 2012 Link to this post

    Hello,

    I'm trying to change the Legenditem text color without expression blend.
    When the enduser clicks a button the foreground color of the legenditem needs to go black, another button turns it white.

    Kind regards,

    Jeroen
  2. Lancelot
    Lancelot avatar
    251 posts
    Member since:
    Jul 2012

    Posted 05 Jun 2012 Link to this post

     
  3. DevCraft banner
  4. Lancelot
    Lancelot avatar
    251 posts
    Member since:
    Jul 2012

    Posted 05 Jun 2012 Link to this post

    Hi Jeroen,

    Here is a list of the properties that make up the ChartLegendStyle:

  5. LegendForeground - a brush, that represent the foreground color of the ChartLegend.
  6. LegendBackground - a brush, that represents the background color of the ChartLegend.
  7. LegendBorderBrush - a brush, that represents the border color of the ChartLegend.
  8. LegendBorderThickness - represents the thickness of the border around the ChartLegend.
  9. LegendItemMarkerShape - represents the shape of the marker inside the ChartLegend's item.
  10. ChartLegendStyle - the Style, applied to the ChartLegend control.
  11.  

    And here is the list of properties that make up the ChartLegendItemStyle:

  12. LegendForeground - a brush, that represents the foreground color of the ChartLegendItem.
  13. LegendItemMarkerMask - a brush, that represents the background of the mask element for the ChatLegendItem's marker.
  14. LegendItemMarkerMaskStroke - a brush, that represents the border color of the mask element for the ChatLegendItem's marker.
  15. LegendItemMarkerMaskStrokeThickness - that represents the thickness of the border of the mask element for the ChatLegendItem's marker.
  16. LegendItemMarkerMaskStroke - a brush, that represents the opacity mask of the mask element for the ChatLegendItem's marker.
  17. LegendItemMarkerMask - a brush, that represents the background of the secondary mask element for the ChatLegendItem's marker.
  18. ChartLegendItemStyle - the Style, applied to the ChartLegendItem control.
  19. You can access them from the code behind in a button_click event by iterating through the visual tree for the type Telerik.Windows.Controls.Charting.ChartLegend  and then the legend items with Telerik.Windows.Controls.Charting.LegendItem.


    Once you iterate for each type, you can then assign a brush to it. in your case it would be

    legendItem.Foreground = new SolidcolorBrush(Colors.Black);

    and also

    legendItem.Foreground = new SolidcolorBrush(Colors.White);

    I hope this helps, good luck!

    Lancelot

  • Answer
    Rosko
    Admin
    Rosko avatar
    137 posts

    Posted 06 Jun 2012 Link to this post

    Hi Jeroen,

    There are two possible ways to solve your issue. The first one is to make your own style where you bind the Foreground color to a property in your object. 
    The other way is what Lancelot suggested -  to set it through the visual tree. Here's an example:

    private void Button_Click(object sender, RoutedEventArgs e)
            {
                var legend = this.radChart.FindChildByType<Telerik.Windows.Controls.Charting.ChartLegend>();
                var legendItems = legend.ItemsSource.Cast<Telerik.Windows.Controls.Charting.ChartLegendItem>();
                 
                foreach (var item in legendItems)
                {
                    item.Background = new SolidColorBrush(Colors.Red);
                }
     
            }


    Greetings,
    Rosko
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  • Back to Top