一定记得要让DataList的Width等于父元素的实际宽度,然后设置每列Column具体的Width宽度时
(例如 Width="1*;Width="30"),才不会出现问题:
<Grid x:Name="GridOne">
<DataGrid ItemsSource="{Binding Table}" Width="{Binding
ElementName=GridOne,Path=ActualWidth}" >
<DataGrid.Columns>
<DataGridTextColumn Width="1*" Header="列1" Binding="
{Binding Property1}" />
<DataGridTextColumn Width="2*" Header="列2" Binding="
{Binding Property2}" />
</DataGrid.Columns>
</DataGrid>
</Grid>
如果父级元素(例如图上的Grid)没有设置具体的宽度大小例如Width=“200”,DataGrid就得Path=ActualWidth,而不是=Width
本文介绍了在使用DataGrid时,如何确保其宽度与父元素保持一致,避免问题,特别是当父元素未指定固定宽度时,需使用ActualWidth属性进行动态调整,同时详细说明了如何设置列宽度。
1158

被折叠的 条评论
为什么被折叠?



