I have the following XAML code I'm using to generate my Series and Graphs.
<
telerik:RadCartesianChart
x:Name
=
"Chart"
HorizontalAlignment
=
"Stretch"
VerticalAlignment
=
"Stretch"
>
<
telerik:RadCartesianChart.ContextMenu
>
<
ContextMenu
>
<
MenuItem
Header
=
"Export to Image"
Click
=
"MenuItem_Click"
/>
</
ContextMenu
>
</
telerik:RadCartesianChart.ContextMenu
>
<
telerik:RadCartesianChart.Behaviors
>
<
telerik:ChartPanAndZoomBehavior
DragMode
=
"Zoom"
ZoomMode
=
"Horizontal"
/>
</
telerik:RadCartesianChart.Behaviors
>
<
telerik:RadCartesianChart.Grid
>
<
telerik:CartesianChartGrid
MajorLinesVisibility
=
"XY"
/>
</
telerik:RadCartesianChart.Grid
>
<
telerik:RadCartesianChart.Resources
>
<
Style
TargetType
=
"telerik:LineSeries"
>
<
Setter
Property
=
"StrokeThickness"
Value
=
"1"
/>
<
Setter
Property
=
"Stroke"
Value
=
"{Binding ValueColour}"
/>
<
Setter
Property
=
"RenderOptions"
Value
=
"{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=DataContext.RenderOptions, Mode=OneWay}"
/>
<
Setter
Property
=
"LegendSettings"
>
<
Setter.Value
>
<
telerik:SeriesLegendSettings
>
<
telerik:SeriesLegendSettings.Title
>
<
MultiBinding
Converter
=
"{StaticResource MultiBindingStringConverter}"
>
<
Binding
Path
=
"ValueName"
/>
<
Binding
Path
=
"Unit"
/>
</
MultiBinding
>
</
telerik:SeriesLegendSettings.Title
>
</
telerik:SeriesLegendSettings
>
</
Setter.Value
>
</
Setter
>
<
Setter
Property
=
"ShowLabels"
Value
=
"False"
/>
<
Setter
Property
=
"VerticalAxis"
>
<
Setter.Value
>
<
MultiBinding
Converter
=
"{StaticResource UnitToVerticalAxisConverter}"
>
<
Binding
Path
=
"ValueName"
/>
<
Binding
Path
=
"Unit"
/>
</
MultiBinding
>
</
Setter.Value
>
</
Setter
>
</
Style
>
<
Style
TargetType
=
"telerik:PointSeries"
>
<
Setter
Property
=
"DefaultVisualStyle"
>
<
Setter.Value
>
<
Style
TargetType
=
"Path"
>
<
Setter
Property
=
"Fill"
Value
=
"{Binding ValueColour, Converter={StaticResource StringToSolidColorBrushConverter}}"
/>
<!-- CAUSES AN INVALID CAST EXCEPTION -->
</
Style
>
</
Setter.Value
>
</
Setter
>
<
Setter
Property
=
"RenderOptions"
Value
=
"{Binding RelativeSource={RelativeSource AncestorType=UserControl, Mode=FindAncestor}, Path=DataContext.RenderOptions, Mode=OneWay}"
/>
<
Setter
Property
=
"LegendSettings"
>
<
Setter.Value
>
<
telerik:SeriesLegendSettings
>
<
telerik:SeriesLegendSettings.Title
>
<
MultiBinding
Converter
=
"{StaticResource MultiBindingStringConverter}"
>
<
Binding
Path
=
"ValueName"
/>
<
Binding
Path
=
"Unit"
/>
</
MultiBinding
>
</
telerik:SeriesLegendSettings.Title
>
</
telerik:SeriesLegendSettings
>
</
Setter.Value
>
</
Setter
>
<
Setter
Property
=
"ShowLabels"
Value
=
"False"
/>
<
Setter
Property
=
"VerticalAxis"
>
<
Setter.Value
>
<
MultiBinding
Converter
=
"{StaticResource UnitToVerticalAxisConverter}"
>
<
Binding
Path
=
"ValueName"
/>
<
Binding
Path
=
"Unit"
/>
</
MultiBinding
>
</
Setter.Value
>
</
Setter
>
</
Style
>
</
telerik:RadCartesianChart.Resources
>
<
telerik:RadCartesianChart.SeriesProvider
>
<
telerik:ChartSeriesProvider
Source
=
"{Binding Series}"
>
<
telerik:ChartSeriesProvider.SeriesDescriptors
>
<
telerik:CategoricalSeriesDescriptor
ItemsSourcePath
=
"Data.Collection"
TypePath
=
"SeriesType"
CategoryPath
=
"Time"
ValuePath
=
"Value"
/>
</
telerik:ChartSeriesProvider.SeriesDescriptors
>
</
telerik:ChartSeriesProvider
>
</
telerik:RadCartesianChart.SeriesProvider
>
<
telerik:RadCartesianChart.HorizontalAxis
>
<
telerik:DateTimeContinuousAxis
MajorStepUnit
=
"Minute"
LabelInterval
=
"4"
FontFamily
=
"Segoe UI"
PlotMode
=
"OnTicks"
LabelFitMode
=
"MultiLine"
>
<
telerik:DateTimeContinuousAxis.LabelTemplate
>
<
DataTemplate
>
<
TextBlock
Text
=
"{Binding Converter={StaticResource MultiLineDateTimeConverter}}"
/>
</
DataTemplate
>
</
telerik:DateTimeContinuousAxis.LabelTemplate
>
</
telerik:DateTimeContinuousAxis
>
</
telerik:RadCartesianChart.HorizontalAxis
>
</
telerik:RadCartesianChart
>
Unfortunately when I try to bind the "ValueColour" property on my PointSeries style, for the Path style's Fill property, I get an invalid cast exception.
My ValueColour Property is of type String and I have tried using converters for both String to Color and String to SolidColorBrush and neither of them are working. The cast exception I get says:
Additional information: Unable to cast object of type 'System.Windows.Data.Binding' to type 'System.Windows.Media.Brush'.
However it works if I hard-code the colour with the value "Red" for example.
How do I make this data-bindable?