|
…
DataTemplate template = new DataTemplate();
template.DataType = typeof(StackPanel);
FrameworkElementFactory stackpanel = new FrameworkElementFactory(typeof(StackPanel));
stackpanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
FrameworkElementFactory textblock = new FrameworkElementFactory(typeof(TextBlock));
textblock.SetBinding(TextBlock.ForegroundProperty, new Binding("Interior"));
textblock.SetValue(TextBlock.FontWeightProperty, FontWeights.Bold);
textblock.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
textblock.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
textblock.SetValue(TextBlock.MarginProperty, new Thickness(0, 0, 0, 0));
AdornmentLabelConverter labelConverter = new AdornmentLabelConverter();
Binding binding = new Binding();
binding.Converter = labelConverter;
textblock.SetBinding(TextBlock.TextProperty, binding);
stackpanel.AppendChild(textblock);
//set the visual tree of the data template
template.VisualTree = stackpanel;
ChartAdornmentInfo adornmentInfo = new ChartAdornmentInfo()
{
ShowLabel = true,
LabelPosition = AdornmentsLabelPosition.Center,
AdornmentsPosition = AdornmentsPosition.Top,
ShowConnectorLine = true,
ConnectorHeight = 10,
SegmentLabelContent = LabelContent.LabelContentPath,
LabelTemplate = template
};
Style style = new Style(typeof(Path));
style.Setters.Add(new Setter(Path.StrokeProperty, Brushes.Transparent));
adornmentInfo.ConnectorLineStyle = style;
series1.AdornmentsInfo = adornmentInfo;
… |
|
public class AdornmentLabelConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
ChartAdornment adornment = value as ChartAdornment;
Model model = adornment.Item as Model;
if (model != null)
{
return model.YValue < 10 ? model.YValue.ToString() : string.Empty;
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
} |
|
<syncfusion:LineSeries x:Name="series1" ItemsSource="{Binding Data}"
XBindingPath="XValue" YBindingPath="YValue"
Label="LineSeries"/> |