or
<
Window
x:Class
=
"LabelTemplate_MultiBinding.MainWindow"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
xmlns:local
=
"clr-namespace:LabelTemplate_MultiBinding"
Title
=
"MainWindow"
Height
=
"768"
Width
=
"1024"
>
<
Grid
>
<
telerik:RadCartesianChart
x:Name
=
"PropertyChart"
>
<
telerik:RadCartesianChart.Resources
>
<
local:ChartNumberFormatter
x:Key
=
"NumberFormatter"
/>
<
DataTemplate
x:Key
=
"FormattedNumericAxisTemplate"
>
<!-- This uses the converter sending the desired value, and it works fine -->
<!--<TextBlock Text="{Binding ., Converter={StaticResource NumberFormatter}}" />-->
<!-- This uses the converter sending some value via binding using ElementName,
and it works fine -->
<!--<
TextBlock
Text="{Binding
Path
=
DataContext
.JustANumber,
Converter={StaticResource NumberFormatter},
ElementName
=
PropertyChart
}" />-->
<!-- This uses the converter sending the same value as above via binding,
but using RelativeSource instead, and it displays incorrectly! -->
<
TextBlock
Text="{Binding
Path
=
DataContext
.JustANumber,
Converter={StaticResource NumberFormatter},
RelativeSource={RelativeSource AncestorType={x:Type telerik:RadCartesianChart}}}" />
</
DataTemplate
>
</
telerik:RadCartesianChart.Resources
>
<
telerik:RadCartesianChart.HorizontalAxis
>
<
telerik:DateTimeCategoricalAxis
/>
</
telerik:RadCartesianChart.HorizontalAxis
>
<
telerik:RadCartesianChart.VerticalAxis
>
<
telerik:LinearAxis
LabelTemplate
=
"{StaticResource FormattedNumericAxisTemplate}"
/>
</
telerik:RadCartesianChart.VerticalAxis
>
<
telerik:RadCartesianChart.Series
>
<
telerik:LineSeries
CategoryBinding
=
"Date"
ValueBinding
=
"Value"
ItemsSource
=
"{Binding Path=Series1}"
>
</
telerik:LineSeries
>
</
telerik:RadCartesianChart.Series
>
</
telerik:RadCartesianChart
>
</
Grid
>
</
Window
>
using
System;
using
System.Collections.Generic;
using
System.Windows;
using
System.Windows.Data;
namespace
LabelTemplate_MultiBinding
{
public
class
MyPoint
{
public
DateTime Date {
get
;
set
; }
public
Double Value {
get
;
set
; }
}
public
partial
class
MainWindow : Window
{
public
List<MyPoint> Series1 {
get
;
private
set
; }
public
string
DisplaySuffix {
get
;
private
set
; }
public
double
JustANumber {
get
;
private
set
; }
public
MainWindow()
{
Series1 =
new
List<MyPoint>();
DisplaySuffix =
"M"
;
JustANumber = 50000;
for
(
int
i = 0; i < 5; i++)
{
DateTime date = DateTime.Today.AddDays(i);
Series1.Add(
new
MyPoint() { Date = date, Value = i * 1000 });
}
InitializeComponent();
DataContext =
this
;
}
}
public
class
ChartNumberFormatter : IValueConverter
{
public
object
Convert(
object
value, Type targetType,
object
parameter, System.Globalization.CultureInfo culture)
{
double
number = System.Convert.ToDouble(value);
return
number.ToString(
"N0"
);
}
public
object
ConvertBack(
object
value, Type targetType,
object
parameter, System.Globalization.CultureInfo culture)
{
throw
new
NotImplementedException();
}
}
}