Questions tagged «gridviewcolumn»

10
如何在WPF中自动调整GridViewColumn数据的大小并使其右对齐?
我怎么能够: 右对齐ID列中的文本 根据具有最长可见数据的单元格的文本长度,使各列自动调整大小? 这是代码: <ListView Name="lstCustomers" ItemsSource="{Binding Path=Collection}"> <ListView.View> <GridView> <GridViewColumn Header="ID" DisplayMemberBinding="{Binding Id}" Width="40"/> <GridViewColumn Header="First Name" DisplayMemberBinding="{Binding FirstName}" Width="100" /> <GridViewColumn Header="Last Name" DisplayMemberBinding="{Binding LastName}"/> </GridView> </ListView.View> </ListView> 部分答案: 感谢Kjetil,GridViewColumn.CellTemplate可以很好地工作,自动宽度也可以正常工作,但是当ObservativeCollection“ Collection”用比列宽长的数据更新时,列大小不会自动更新,因此这仅仅是解决方案初始显示数据: <ListView Name="lstCustomers" ItemsSource="{Binding Path=Collection}"> <ListView.View> <GridView> <GridViewColumn Header="ID" Width="Auto"> <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Id}" TextAlignment="Right" Width="40"/> </DataTemplate> …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.