Hi,
I want to use the properties from my CustomLabelPoint at the style of the label.
Here is some example code wich doesn´t work because the LabelFunc have to return a string.
Is it possible that the LabelFunc maybe can return an object?
Or ist there another solution?
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Chart.IsAxisBaselineVisible = false;
Chart.IsLegendVisible = false;
LineSeries.LabelVisibility = LabelVisibility.Visible;
LineSeries.ItemsSource = new List<CustomLabelPoint> {new CustomLabelPoint(1, 0, "A", "A1"), new CustomLabelPoint(5, 0, "B", "B1")};
LineSeries.LabelFunc = LabelFunc;
}
private string LabelFunc(object o, object o1, object arg3, object arg4, object arg5)
{
return ((CustomLabelPoint) arg5).TextA;
}
}
public class CustomLabelPoint
{
public double X { get; set; }
public double Y { get; set; }
public string TextA { get; set; }
public string TextB { get; set; }
public CustomLabelPoint(double x, double y, string text, string text2)
{
TextA = text;
TextB = text2;
X = x;
Y = y;
}
}
<Style TargetType="charts:DataPointLabel" x:Key="LabelStyle">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Foreground" Value="{Binding SeriesDefaultBrush}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="charts:DataPointLabel">
<Border Background="White">
<ContentPresenter x:Name="PART_ContentPresenter" Margin="{TemplateBinding Padding}">
<ContentPresenter.ContentTemplate>
<DataTemplate DataType="app:CustomLabelPoint">
<StackPanel>
<TextBlock Width="50" Height="50" Background="Aqua" Text="{Binding <strong>TextA</strong>}"></TextBlock>
<TextBlock Width="50" Height="50" Background="Aqua" Text="{Binding <strong>TextB</strong>}"></TextBlock>
</StackPanel>
</DataTemplate>
</ContentPresenter.ContentTemplate>
</ContentPresenter>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>