Binding values from custom label

Charts for WPF Forum

Posted 10 years ago by Lukas Lober
Version: 13.2.0591
Avatar

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>

Comments (2)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

In our product, only string-based labels are supported.  That being said, you can return things like line terminators in the string to make a two-line value.  We do that in our Data Point Labels QuickStart code-behind for the custom label function example in that:

public static string GetCustomLabel(object primaryValue, object secondaryValue, object xValue, object yValue, object originalValue) {
	return string.Format("X: {0}{1}Y: {2}", xValue, Environment.NewLine, yValue);
}


Actipro Software Support

Posted 10 years ago by Lukas Lober
Avatar

Thanks for the reply.

Not exactly what I was looking for but it helped me.

I´m now using a value converter to split the string.

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.