C# 如何使单元格在WPF网格中向右或向左对齐时具有全宽
我正在WPF中设计一些网格,希望显示向右对齐的数字,但当我设置HorizontalAlignment=right时,单元格本身并没有使用所有可用宽度,因此边框根据内容绘制一半。看附件中的图片 代码是:C# 如何使单元格在WPF网格中向右或向左对齐时具有全宽,c#,wpf,datagrid,grid-layout,C#,Wpf,Datagrid,Grid Layout,我正在WPF中设计一些网格,希望显示向右对齐的数字,但当我设置HorizontalAlignment=right时,单元格本身并没有使用所有可用宽度,因此边框根据内容绘制一半。看附件中的图片 代码是: <Grid Width="620" Name="tblTaxBalance"> <Grid.ColumnDefinitions> <ColumnDefinition Width="110"/> <ColumnDef
<Grid Width="620" Name="tblTaxBalance">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="110"/>
<ColumnDefinition Width="350"/>
<ColumnDefinition Width="80" Style="{StaticResource CellRightAlign}"/>
<ColumnDefinition Width="80" Style="{StaticResource CellRightAlign}"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- row 1 -->
<Label Grid.RowSpan="2" Grid.Row="0" Style="{StaticResource TaxTableCellStyle}" BorderThickness="1">Тайлангийн төрөл</Label>
<Label Grid.RowSpan="2" Grid.Row="0" Grid.Column="1" Style="{StaticResource TaxTableCellStyle}" BorderThickness="0,1,1,1">Татварын төрөл</Label>
<Label Grid.ColumnSpan="2" Grid.Row="0" Grid.Column="2" Style="{StaticResource TaxTableCellStyle}" BorderThickness="0,1,1,1">Эцсийн үлдэгдэл /мян. төг/</Label>
<!-- row 2 -->
<Label Grid.RowSpan="2" Grid.Row="1" Grid.Column="2" Style="{StaticResource TaxTableCellStyle}" BorderThickness="0,0,1,1" HorizontalAlignment="Right">Дутуу</Label>
<Label Grid.RowSpan="2" Grid.Row="1" Grid.Column="3" Style="{StaticResource TaxTableCellStyle}" BorderThickness="0,0,1,1">Илүү</Label>
</Grid>
Тайлангийн төрөл
Татварын төрөл
Эцсийн үлдэгдэл /мян. төг/
Дутуу
Илүү
使用水平对齐拉伸并将流动方向从右设置为左
就像这样:
<Label Grid.RowSpan="2" Grid.Row="1" Grid.Column="2" Style="{StaticResource TaxTableCellStyle}" BorderThickness="0,0,1,1" HorizontalAlignment="Stretch" FlowDirection="RightToLeft">Дутуу</Label>
<代码>ааа
您可以显示您的样式CellAlignRight吗?您可以忽略CellAlignRight,它具有HorizontalAlignment=“Right”。谢谢,FlowDirection=“RightToLeft”修复了所有问题。