如何在FlowDocument中绘制带图形线的Table?

问题描述 投票:0回答:2

在我的 FlowDocument 中,我想包含一个充满文本和图表线的表格。您会推荐哪种方法?我正在考虑将装饰器附加到桌子上,但到目前为止我无法完成将装饰器附加到整个桌子上。

这是我要添加到文档中的内容的草图:

enter image description here

我正在使用 C# 和 .NET 4.0

c# graph drawing flowdocument
2个回答
2
投票

问题通过Grid解决了。 Grid和Table很相似,包含一个Canvas也没有问题。在这里您可以看到示例图像,以及将 Grid 与 Canvas 一起放入 FlowDocument 中的示例。您也可以通过代码创建相同的流程文档:

Table with multiple rows, columns and drawing in the cells.

<FlowDocument PageWidth="600" MinPageWidth="600" PagePadding="0,0,0,0">
  <Section>
    <Paragraph>
      <Grid ShowGridLines="False" Background="#FFFFFFFF" Margin="0,5,0,0">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="140"/>
          <ColumnDefinition Width="460"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="20"/>
          <RowDefinition Height="20"/>
        </Grid.RowDefinitions>
        <Canvas Background="#FFFFFFFF" Name="Canvas0" Width="460" Height="40" Grid.Column="1" Grid.Row="1">
          <Rectangle Fill="#FFD3D3D3" Width="140" Height="40" Canvas.Left="160" Canvas.Top="0"/>
          <Rectangle Fill="#FFA9A9A9" Width="91" Height="40" Canvas.Left="188" Canvas.Top="0"/>
          <Ellipse Fill="#FF3E00C1" Width="7" Height="7" Canvas.Left="282.978417266187" Canvas.Top="6.5"/>
          <Ellipse Fill="#FF1D00E2" Width="7" Height="7" Canvas.Left="199.508" Canvas.Top="26.5"/>
          <Line X1="286.478417266187" Y1="10" X2="203.008" Y2="30" StrokeThickness="2">
            <Line.Stroke>
              <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                <LinearGradientBrush.GradientStops>
                  <GradientStop Color="#FF1D00E2" Offset="0"/>
                  <GradientStop Color="#FF3E00C1" Offset="1"/>
                </LinearGradientBrush.GradientStops>
              </LinearGradientBrush>
            </Line.Stroke>
          </Line>
        </Canvas>
      </Grid>
    </Paragraph>
  </Section>
</FlowDocument>

0
投票

Я использую такой подход。 работа идёт с каждой отдельной ячейкой。 В ресурсах。

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style x:Key="BaseBorder" TargetType="TableCell">
        <Setter Property="BorderBrush" Value="Black"/>
    </Style>

    <Style TargetType="TableCell" BasedOn="{StaticResource BaseBorder}">
        <Setter Property="BorderThickness" Value="1,1,0,0" />
    </Style>

    <Style x:Key="BorderLastColumn" TargetType="TableCell" BasedOn="{StaticResource BaseBorder}">
        <Setter Property="BorderThickness" Value="1,1,1,0" />
    </Style>

    <Style x:Key="BorderLastRow" TargetType="TableCell" BasedOn="{StaticResource BaseBorder}">
        <Setter Property="BorderThickness" Value="1,1,0,1" />
    </Style>

    <Style x:Key="BorderLastRowColumn" TargetType="TableCell" BasedOn="{StaticResource BaseBorder}">
        <Setter Property="BorderThickness" Value="1,1,1,1" />
    </Style>

</ResourceDictionary>

И в коде。

rowLast.Cells.Add(new(new Paragraph(new Run("Test")) { Style = (Style)Resources["BorderLastColumn"] });
© www.soinside.com 2019 - 2024. All rights reserved.