我希望将页眉格式设置成如图所示(第一行为INWARD,第二行为毛重、净重和数量)。我可以在XAML中通过以下代码实现,但是我该如何通过编程实现呢?
XAML:
<dg:DataGrid>
<dg:DataGridTemplateColumn Width="210">
<dg:DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Text="INWARD"
TextAlignment="Center">
</TextBlock>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<TextBlock Width="80"
Text="Gross Weight"
TextAlignment="Right"
Margin="0,0,2,0">
</TextBlock>
<TextBlock Width="80"
Text="Pure Weight"
TextAlignment="Right"
Margin="0,0,0,0">
</TextBlock>
<TextBlock Width="40"
Text="Quantity"
TextAlignment="Right"
Margin="2,0,0,0">
</TextBlock>
</StackPanel>
</Grid>
</DataTemplate>
</dg:DataGridTemplateColumn.HeaderTemplate>
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<TextBlock Style="{DynamicResource grdCellCurrencyData}"
Width="80"
Margin="0,0,2,0">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource CurrencyConverter}" ConverterParameter="True">
<Binding Path="INGrossWeight" Mode="OneWay" />
<Binding Path="BaseUOMNoofDecimals" Mode="OneWay" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock Style="{DynamicResource grdCellCurrencyData}"
Width="80"
Margin="0,0,0 0">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource CurrencyConverter}" ConverterParameter="True">
<Binding Path="INPureWeight" Mode="OneWay" />
<Binding Path="BaseUOMNoofDecimals" Mode="OneWay" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock Style="{DynamicResource grdCellCurrencyData}"
Width="40"
Text="{Binding Path=INQuantity, Mode=OneWay}" Margin="2,0,0,0">
</TextBlock>
</StackPanel>
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
</dg:DataGrid>
在上面的代码中,如果您查看DataGridTemplateColumn
,我已经将网格放在内部并将标题拆分为两行。同样的方式,我想从后台代码进行编程。有人可以帮忙吗?