請嘗試這種解決辦法:
<ListView>
<ListView.View>
<GridView>
<GridViewColumn Header="column1" x:Name="col1"/>
<!--Column that shall resize: Width is set to the Actual Width of the helper field defined below-->
<GridViewColumn Header="column2"
Width="{Binding ElementName=helperField, Path=ActualWidth}"/>
</GridView>
</ListView.View>
Test Text
</ListView>
<!--This is the hidden helper Grid which does the resizing -->
<Grid Visibility="Hidden">
<Grid.ColumnDefinitions>
<!--Width is bound to width of the first GridViewColumn -->
<ColumnDefinition Width="{Binding ElementName=col1, Path=ActualWidth}"/>
<!--Width is set to "Fill"-->
<ColumnDefinition Width="*"/>
<!--Correction Width-->
<ColumnDefinition Width="10"/>
</Grid.ColumnDefinitions>
<!--This is the hidden helper Field which is used to bind to, using the "Fill" column of the helper grid-->
<Grid Grid.Column="1" x:Name="helperField"/>
</Grid>
你也可以找到在以下鏈接一些其他的解決辦法:
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/3ee5696c-4f26-4e30-8891-0e2f95d69623/
感謝比拉爾哈什米用於數據HTML視圖。但是在上面的xaml方法中,我應該在我的xaml頁面中放置一行代碼,以便它會影響ListView列。使用IValueConverter時,它很好地工作,當第一次屏幕加載時,但是當我最大化屏幕或調整大小屏幕時,它不會相應地調整列寬。 –
Yogesh
2012-04-25 05:32:43
也許這可能有助於http://stackoverflow.com/questions/560581/how-to-autosize-and-right-align-gridviewcolumn-data-in-wpf – Klaus78 2012-04-25 05:47:21
你可以把它放在你正在顯示的xaml頁面的任何地方你的ListView。可以說在頁面主柵格的行= 0和列= 0。 – 2012-04-25 09:52:33