.net 删除WPF DATAGRID中的空白列
我使用数据集在WPF(C#)中填充数据网格。结果是: 我想删除左侧的空白列。我想将剩余空间共享给列。预期结果是: 我的XAML代码是:.net 删除WPF DATAGRID中的空白列,.net,wpf,xaml,datagrid,.net,Wpf,Xaml,Datagrid,我使用数据集在WPF(C#)中填充数据网格。结果是: 我想删除左侧的空白列。我想将剩余空间共享给列。预期结果是: 我的XAML代码是: <Window x:Class="RFID.CareerWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<Window x:Class="RFID.CareerWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="CareerWindow" Height="356" Width="404">
<Grid>
<DataGrid x:Name="dg1" HorizontalAlignment="Left" Margin="25,10,0,0" VerticalAlignment="Top" Height="306" Width="355" EnableRowVirtualization="false" EnableColumnVirtualization="false" FontFamily="2 badr" FontSize="20" FlowDirection="RightToLeft" CanUserAddRows="False" CanUserReorderColumns="False"/>
</Grid>
</Window>
避免设置静态高度和宽度 使用
ColumnWidth=“*”
在DataGridColumns之间共享空间
<DataGrid x:Name="dg1" ColumnWidth="*"
HorizontalAlignment="Left" VerticalAlignment="Top" Margin="25,10,0,0"
EnableRowVirtualization="false" EnableColumnVirtualization="false"
FontFamily="2 badr" FontSize="20" FlowDirection="RightToLeft"
CanUserAddRows="False" CanUserReorderColumns="False" />
您可以使用设置网格的最后一列或一列
<DataGridTextColumn Header="Surname"
Width="*"
Binding="{Binding Path=Surname,Mode=TwoWay}" IsReadOnly="True">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
它工作得非常好!非常感谢。现在,你能帮我把所有的文本(单元格和标题)对齐为中心吗?请检查这篇文章以对齐单元格文本。这篇文章将对齐标题内容。