В нашем приложении мы используем не XAML, а код C #, поэтому, пожалуйста, помогите мне преобразовать этот код XAML в C #.
@"<Style TargetType='charting:LineDataPoint'>
<Setter Property='Background' Value='Blue'/>
<Setter Property='Width' Value='7' />
<Setter Property='Height' Value='7' />
<Setter Property='Template'>
<Setter.Value>
<ControlTemplate TargetType='charting:LineDataPoint'>
<Grid Opacity='1'>
<ToolTipService.ToolTip>
<StackPanel Margin='2,2,2,2'>
<ContentControl Content='{Binding Path=Key}' ContentStringFormat='" + "Date" + @": {0:d}'/>
<ContentControl Content='{Binding Path=Value}' ContentStringFormat='" + "Max." + @": {0:n}'/>
</StackPanel>
</ToolTipService.ToolTip>
<Ellipse Opacity='1' StrokeThickness='1' Stroke='#FF686868' Fill='{TemplateBinding Background}'/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>";
Вот код, который я пробовал, но когда я его запускаю, я получаю сообщение об ошибке «Подсказка не может иметь логического или визуального родителя».
var styleDataPoint = new Style(typeof(LineDataPoint));
var backGroundSetter = new Setter { Property = BackgroundProperty, Value = Brushes.Blue };
var widthSetter = new Setter { Property = WidthProperty, Value = 10.0 };
var heightSetter = new Setter { Property = HeightProperty, Value = 10.0 };
var dataPointTemplate = new Setter { Property = TemplateProperty };
var template = new ControlTemplate(typeof(LineDataPoint));
var gridElementFactory = new FrameworkElementFactory(typeof(Grid));
gridElementFactory.SetValue(NameProperty, "Root");
gridElementFactory.SetValue(OpacityProperty, 1.0);
var toolTiplElementFactory = new FrameworkElementFactory(typeof(ToolTip));
var stackPanelElementFactory = new FrameworkElementFactory(typeof(StackPanel));
stackPanelElementFactory.SetValue(MarginProperty, new Thickness(2, 2, 2, 2));
var tooltipLine = new FrameworkElementFactory(typeof(ContentControl));
tooltipLine.SetValue(ContentStringFormatProperty, "Min." + @": {0:d}");
tooltipLine.SetBinding(ContentProperty, new Binding("Key"));
stackPanelElementFactory.AppendChild(tooltipLine);
var tooltipLine1 = new FrameworkElementFactory(typeof(ContentControl));
tooltipLine1.SetValue(ContentStringFormatProperty, "Max." + @": {0:n}");
tooltipLine1.SetBinding(ContentProperty, new Binding("Value"));
stackPanelElementFactory.AppendChild(tooltipLine1);
toolTiplElementFactory.AppendChild(stackPanelElementFactory);
var ellipselElementFactory = new FrameworkElementFactory(typeof(Ellipse));
ellipselElementFactory.SetValue(OpacityProperty, 1.0);
ellipselElementFactory.SetValue(Shape.StrokeThicknessProperty, 1.0);
ellipselElementFactory.SetValue(Shape.FillProperty, Brushes.Blue);
gridElementFactory.AppendChild(toolTiplElementFactory);
gridElementFactory.AppendChild(ellipselElementFactory);
template.VisualTree = gridElementFactory;
dataPointTemplate.Value = template;
styleDataPoint.Setters.Add(backGroundSetter);
styleDataPoint.Setters.Add(widthSetter);
styleDataPoint.Setters.Add(heightSetter);
styleDataPoint.Setters.Add(dataPointTemplate);