HTML喜欢表格使用网格? [英] HTML Like Table Using Grid?

查看:70
本文介绍了HTML喜欢表格使用网格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,我需要生成一张发票,因此,我需要使用支持Grid UIElement的WPF FixedDocument来打印表格.现在,我想像HTML表格一样使用Grid来构建用户友好的发票.

Hi friends, i am in a need to build an invoice and for that reason I need a Table to be printed using WPF FixedDocument which supports Grid UIElement. Now I want to use Grid as just like HTML table in order to build a user friendly Invoice.


推荐答案

您可能要考虑使用DataGrid控件.但是,如果必须使用网格,则可以将以下内容作为起点:

You may want to consider using DataGrid control instead. But if you must use a Grid, you may consider the following as a starting point:

 

  <Grid>
    <Grid.Resources>
      <Style TargetType="Label">
        <Setter Property="Margin" Value="5" />
        <Setter Property="HorizontalAlignment" Value="Center" />
      </Style>
    </Grid.Resources>
    <!-- Defining 6 columns and their width -->
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="80"/>
      <ColumnDefinition Width="150"/>
      <ColumnDefinition Width="80"/>
      <ColumnDefinition Width="80"/>
      <ColumnDefinition Width="130"/>
      <ColumnDefinition Width="110"/>
    </Grid.ColumnDefinitions>
    <!-- You need to specify how many rows you'll need -->
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <!-- Simulating table borders, it spans all of the 6 columns but spans N-1 rows. Row N is to show the totals. -->
    <Rectangle Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Grid.ColumnSpan="6"
          Stroke="Black" StrokeThickness="3" RadiusX="5" RadiusY="5" />
    
    <!-- First row is the column headers -->
    <Label Grid.Row="0" Grid.Column="0" Content="Quantity"/>
    <Label Grid.Row="0" Grid.Column="1" Content="Description of Goods"/>
    <Label Grid.Row="0" Grid.Column="2" Content="Unit Price"/>
    <Label Grid.Row="0" Grid.Column="3" Content="Value"/>
    <Label Grid.Row="0" Grid.Column="4" Content="Amount of CED"/>
    <Label Grid.Row="0" Grid.Column="5" Content="Total Value"/>
    
    <!-- The remaining rows are the values -->
    <Label Grid.Row="1" Grid.Column="0" Content="1"/>
    <Label Grid.Row="1" Grid.Column="1" Content="2"/>
    <Label Grid.Row="1" Grid.Column="2" Content="3"/>
    <Label Grid.Row="1" Grid.Column="3" Content="4"/>
    <Label Grid.Row="1" Grid.Column="4" Content="5"/>
    <Label Grid.Row="1" Grid.Column="5" Content="6"/>

    <!-- Total values values -->
    <Label Grid.Row="2" Grid.Column="0" Content="Total:" HorizontalAlignment="Left"/>
    <Label Grid.Row="2" Grid.Column="3" Content="TotalValue"/>
    <Label Grid.Row="2" Grid.Column="4" Content="TotalCEDAmount"/>
    <Label Grid.Row="2" Grid.Column="5" Content="TotalTotalValue"/>
  </Grid>


这篇关于HTML喜欢表格使用网格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆