Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
';工具提示';将XAML转换为C#代码时不能出现逻辑或可视父级错误_C#_Xaml - Fatal编程技术网

';工具提示';将XAML转换为C#代码时不能出现逻辑或可视父级错误

';工具提示';将XAML转换为C#代码时不能出现逻辑或可视父级错误,c#,xaml,C#,Xaml,在我们的应用程序中,我们不使用XAML,而是使用C#代码,因此请帮助我将此XAML代码转换为C# 不久前我遇到了类似的情况,我读到(=意识到)不应该自己构建可视化树,因为它是一个普通的DOM。相反,您应该使用模板,即使用代码(例如C#)创建模板,然后应用它 换句话说,尽管有一个不推荐使用的API,但只需遵循-way即可。我个人不喜欢依赖一些没有价值的东西,但这似乎是实现你所需要的最好方式 然而,“最好”的方法是使用XAML 干杯您的应用程序看起来像一个WPF应用程序,这个问题的简单答案是,如果您

在我们的应用程序中,我们不使用XAML,而是使用C#代码,因此请帮助我将此XAML代码转换为C#


不久前我遇到了类似的情况,我读到(=意识到)不应该自己构建可视化树,因为它是一个普通的DOM。相反,您应该使用模板,即使用代码(例如C#)创建模板,然后应用它

换句话说,尽管有一个不推荐使用的API,但只需遵循-way即可。我个人不喜欢依赖一些没有价值的东西,但这似乎是实现你所需要的最好方式

然而,“最好”的方法是使用XAML


干杯

您的应用程序看起来像一个WPF应用程序,这个问题的简单答案是,如果您希望使用XAML,那么您的应用程序实际上确实使用了XAML。需要更多的信息,否则这个问题无法按原样回答。通过使用堆栈面板之类的东西,您完全是在使用WPF。如果仍然不使用任何XAML,则很难做到这一点。在我看来,你必须拿出一个很好的理由在WPF应用程序中不使用任何XAML。想详细说明一下吗?谢谢你的快速回复。我们维护的代码库总是被指示使用C#代码隐藏而不是XAML(例外情况除外)。但这是我第一次在执行转换任务时遇到这种类型的错误,它花费了很长时间,但仍然没有成功:(,请帮助。
@"<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);