询问者
ListView能做到第一列的宽度自适应,其余列宽度固定吗?

问题
全部回复
-
你好,
>>ListView的宽度是随窗口宽度变化的。我希望它的第一列能够自动增长,其余列则是保持固定宽度不变,请问如何实现?
我不知你说的自动增长是什么意思,如果是根据文字的长度来自适应的话,可以使用auto 来做, 如果是根据窗体的大小来改变的话,你可以, 你可以定义一个宽度的字段,并绑定到Width属性上,然后在Window_SizeChanged事件中改变这个值。
<ListView x:Name="lstData" ItemsSource="{Binding Products}" Margin="0,20,0,0"> <ListView.View> <GridView> <GridViewColumn Header="Product ID" Width="auto" DisplayMemberBinding="{Binding Path=ProductId}" /> <GridViewColumn Header="Product Name" Width="150" DisplayMemberBinding="{Binding Path=ProductName}" /> <GridViewColumn Header="Price" Width="100" DisplayMemberBinding="{Binding Path=Price}" /> </GridView> </ListView.View> </ListView>
Best regards,
Zhanglong
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.