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

[Solved] Custom ChartPalette Color on TrackInfoTemplate

1 Answer 43 Views
Chart for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mark
Top achievements
Rank 1
Mark asked on 15 Feb 2013, 04:58 PM

I have a custom ChartPalette for my chart which I add series to from the cs file.  I am applying a custom TrackInfo template from the cs file using the following code:

 

 

 

 

 

string templateName = "TrackInfoTemplate";

var

 

 

 

template = this.Resources[templateName] as DataTemplate;

ChartTrackBallBehavior.SetTrackInfoTemplate(IllustrationChart.Series[IllustrationChart.Series.Count - 1], template);


My template looks like the following:

<DataTemplate x:Key="TrackInfoTemplate">

<StackPanel Background="LightGray">

<TextBlock Margin="4" Text="{Binding Series.LegendTitle}" FontSize="11" Foreground="Black" FontWeight="Bold"/>

<TextBlock Text="{Binding DataPoint.Value, Converter={StaticResource ChartLegendConverter}}" FontSize="10" Margin="10 0 0 0" Foreground="Black"/>

</StackPanel>

</DataTemplate>



How can I set the Foreground color of the textblock bound to the Series.Lengend title to match the color of the series itself? 

1 Answer, 1 is accepted

Sort by
0
Ivaylo Gergov
Telerik team
answered on 20 Feb 2013, 04:14 PM
Hello Mark,

Thank you for using our controls.

In this case you can use a converter and change the foreground of the textblock depending on the palette index applied on the current series. Here's a sample setup using the provided code snippet:
<Page.Resources>    
    <local:ForeGroundConverter x:Key="converter"/>
    <DataTemplate x:Key="TrackInfoTemplate">
        <StackPanel Background="LightGray">
            <TextBlock Margin="4" Text="{Binding Series.LegendTitle}" FontSize="11" Foreground="Black" FontWeight="Bold"/>
            <TextBlock Text="{Binding DataPoint.Value}" FontSize="35" Margin="10 0 0 0" Foreground="{Binding Series, Converter={StaticResource converter}}"/>
        </StackPanel>
    </DataTemplate>
</Page.Resources>

And here's the ForegroundConverter class:
public class ForeGroundConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            CartesianSeries series = value as CartesianSeries;
            RadCartesianChart chart = series.Chart as RadCartesianChart;
            int index = chart.Series.IndexOf(series);
            return chart.Palette.StrokeEntries.Brushes[index];
        }
        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }


I hope this helps. Let me know if you need further assistance.

 

Greetings,
Ivaylo Gergov
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
Chart for XAML
Asked by
Mark
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Share this question
or