Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.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
如何在WPF中将图形绘制到DataGrid中?_Wpf_Canvas_Datagrid - Fatal编程技术网

如何在WPF中将图形绘制到DataGrid中?

如何在WPF中将图形绘制到DataGrid中?,wpf,canvas,datagrid,Wpf,Canvas,Datagrid,我想在DataGrid上画一个线图。这将出现在我的网格的第一列上,该图很大,跨越了数据网格上的所有行 我将如何处理这种情况?我应该用帆布吗?如果是这样的话,我应该为每个DataGridCell放置一个小画布,还是可以在DataGrid的顶部渲染一个大画布?好吧,你可以按照你在问题中所说的做,即在网格顶部覆盖另一个控件,等等。但是与滚动同步,调整列/行大小可能是一场噩梦。根据我的经验,做了很多次之后,其中一种更简单的方法(从长远来看,尽管一开始看起来很难)是提取DataGrid模板(使用blend

我想在DataGrid上画一个线图。这将出现在我的网格的第一列上,该图很大,跨越了数据网格上的所有行


我将如何处理这种情况?我应该用帆布吗?如果是这样的话,我应该为每个DataGridCell放置一个小画布,还是可以在DataGrid的顶部渲染一个大画布?

好吧,你可以按照你在问题中所说的做,即在网格顶部覆盖另一个控件,等等。但是与滚动同步,调整列/行大小可能是一场噩梦。根据我的经验,做了很多次之后,其中一种更简单的方法(从长远来看,尽管一开始看起来很难)是提取DataGrid模板(使用blend)并根据需要修改它

提取DataGrid的模板后,您将发现:

....
<ControlTemplate TargetType="{x:Type DataGrid}">
    <Border ...>
       <ScrollViewer Focusable="false" Name="DG_ScrollViewer" Background="{TemplateBinding Background}">
          <ScrollViewer.Template>
             <ControlTemplate TargetType="{x:Type ScrollViewer}">
                  <Grid x:Name="DG_MainGrid" Background="{TemplateBinding Background}">
。。。。
这是放置“SelectAllButton”和滚动条等的网格。您可以在其中放置任何内容,并将其与您获得的任何列对齐:

您可以放置边框并将图形(图表控件)放入其中,通过绑定控制边框宽度、高度、边距等,如下所示:

<Border Grid.Row="2" Grid.ColumnSpan="2" BorderThickness="2"    
        Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Views:MyView}}, Path=ChartBorderWidth}"
        Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Views:MyView}}, Path=ChartBorderHeight}"
        Margin="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Views:MyView}}, Path=ChartBorderMargin}">
        <..your charting control>
</Border>

无论如何,这只是一个建议,当你开始在WPF中做一些定制的事情,而不仅仅是开箱即用的解决方案时,事情太复杂了,无法给你准确的答案。但我希望这有帮助