删除WPF DataGrid中的空白列 [英] Remove the blank column in a WPF DataGrid
本文介绍了删除WPF DataGrid中的空白列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用DataSet在WPF(C#)中填充DataGrid。结果是:
I use a DataSet to populate a DataGrid in WPF (C#). The result is:
我想删除左侧的空白列。而且我想分享一下空间到列。预期的结果是:
I want to remove blank column at left side. And I want to share remaing space to columns. Expected result is:
我的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>
推荐答案
避免设置静态高度和宽度。
Avoid setting static Height and Width.
使用 ColumnWidth =*
共享DataGridColumns之间的空间
Use ColumnWidth="*"
to share the space between your 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" />
这篇关于删除WPF DataGrid中的空白列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文