我想要图像中的格式标题(第一行向内,总重量,纯重量和数量。在第二行)。我可以使用 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
,我已将网格放入内部并将标题拆分为两行。我想以编程方式从后面的代码中执行相同的方式。有人可以帮忙吗?