繁体   English   中英

如何自定义WPF工具包折线图中的每个数据点的工具提示?

[英]How to customize a tooltip for each individual datapoint in a wpf toolkit lineseries chart?

我已经看到了几个有关为单行系列进行自定义工具提示的问题。

我需要每个数据点的自定义工具提示。 我想在工具提示中添加更多内容,而不仅仅是依赖值路径和独立值路径。

示例我在同一行上有2个数据点,一个的值(Y轴)为2,日期(x轴)为4/28/2016,且配置为A。另一个的值为3,日期为2016年4月29日,配置B。

我还将如何显示配置? 这都是在后面的代码中完成的,因为我有动态数量的lineseries。 因此,我不能只为xaml中的每个线系列分配样式。

var MyLineSeries = new LineSeries();
lMyLineSeries.DependentValuePath = "Y";
lMyLineSeries.IndependentValuePath = "X";
lMyLineSeries.DataPointStyle = lToolTipDataPointStyle;

这是我创建工具提示样式的代码。

var lToolTipDataPointStyle = new Style(typeof(LineDataPoint));
var lTemplate = new ControlTemplate(typeof(LineDataPoint));
var lGridElement = new FrameworkElementFactory(typeof(Border));

//Tooltip
var lStackPanel = new StackPanel();

var lValueContentControl = new ContentControl();
lValueContentControl.SetBinding(ContentControl.ContentProperty, new Binding(myLineSeries.DependentValuePath));
lValueContentControl.ContentStringFormat = "Value: {0}";

var lConfigurationContentControl = new ContentControl();
lConfigurationContentControl.SetBinding(ContentControl.ContentProperty, new Binding())//This is what Idk what to bind to???

lConfigurationContentControl.ContentStringFormat = "Configuration: {0}";

lStackPanel.Children.Add(lValueContentControl);
lStackPanel.Children.Add(lConfigurationContentControl);

lGridElement.SetValue(ToolTipService.ToolTipProperty, lStackPanel);


var lEllipseElement = new FrameworkElementFactory(typeof(Ellipse));
lEllipseElement.SetValue(Ellipse.StrokeThicknessProperty, new TemplateBindingExtension(Border.BorderThicknessProperty));
lEllipseElement.SetValue(Ellipse.StrokeProperty, new TemplateBindingExtension(Border.BorderBrushProperty));
lEllipseElement.SetValue(Ellipse.FillProperty, new TemplateBindingExtension(Grid.BackgroundProperty));

lGridElement.AppendChild(lEllipseElement);
lTemplate.VisualTree = lGridElement;

var lTemplateSetter = new Setter();
lTemplateSetter.Property = LineDataPoint.TemplateProperty;
lTemplateSetter.Value = lTemplate;

lToolTipDataPointStyle.Setters.Add(lTemplateSetter);

return lToolTipDataPointStyle;

我通过使用Line系列上的Tag弄清楚了。

myLineSeries.Tag = "Configuration";
var lConfigurationContentControl = new ContentControl();
lConfigurationContentControl.SetBinding(ContentControl.ContentProperty, new Binding(myLineSeries.Tag.ToString()))

lConfigurationContentControl.ContentStringFormat = "Configuration: {0}";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM