在我的ListView WPF应用程序中,我使用的是DataGrid控件而不是DataGrid。我想将*宽度给我的ListView.GridViewColumn,但是每当我向ListView.GridViewColumn提供*宽度时,它就会给我一个编译时错误。请建议我如何提供*宽度给ListView.GridViewColumn,以便ListView.GridViewColumn可以自动填补额外的空间时,我最大化屏幕。
在这方面的任何帮助都将受到高度赞赏。谢谢
发布于 2012-04-25 04:51:55
请试用该解决方案:
<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/
发布于 2012-05-10 00:33:40
我在这里发布了我的方法,这是有点不同的(但发现它非常可靠,并允许百分比宽度列https://stackoverflow.com/a/10526024/41211),因为我尝试了上面的,并发现我的devenv.exe处理最大,因为它不断尝试重新评估我的设计师视图与上述动态绑定。
https://stackoverflow.com/questions/10309249
复制相似问题