wpf ListView.GridViewColumn (*) 宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10309249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ListView.GridViewColumn (*) width
提问by Yogesh
I am using ListView
control instead of DataGrid
in my WPFapplication. I want to give *
width to my ListView.GridViewColumn
, but whenever I am providing *
width to ListView.GridViewColumn
, it gives me a compile time error. Kindly suggest me how can I provide *
width to ListView.GridViewColumn
, so that ListView.GridViewColumn
can automatically fill extra space when I maximize screen.
我正在使用ListView
控件而不是DataGrid
在我的WPF应用程序中。我想给*
宽度我ListView.GridViewColumn
,但每当我提供*
宽度ListView.GridViewColumn
,它给了我一个编译时错误。请建议我如何为 提供*
宽度ListView.GridViewColumn
,以便ListView.GridViewColumn
在最大化屏幕时自动填充额外空间。
Any help on this will highly appreciated. Thanks
对此的任何帮助将不胜感激。谢谢
回答by Bilal Hashmi
Please try that solution:
请尝试该解决方案:
<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>
You could also find some other solution at the following link:
您还可以在以下链接中找到其他解决方案:
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/3ee5696c-4f26-4e30-8891-0e2f95d69623/
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/3ee5696c-4f26-4e30-8891-0e2f95d69623/
回答by GONeale
I posted my approach to this here which is a little different (but found it to be very reliable and allows percentage width columns https://stackoverflow.com/a/10526024/41211) as I tried the above and was finding my devenv.exe processing maxing out as it was constantly trying to re-evaluate my designer view with the above dynamic bindings.
我在这里发布了我的方法,这有点不同(但发现它非常可靠并且允许百分比宽度列https://stackoverflow.com/a/10526024/41211),因为我尝试了上述方法并找到了我的 devenv。 exe 处理最大化,因为它不断尝试使用上述动态绑定重新评估我的设计器视图。
回答by kellorbr
With the group columns view definition, the Kettic GridView allows the users to create column groups view and HTML view for the data in grid
通过组列视图定义,Kettic GridView 允许用户为网格中的数据创建列组视图和 HTML 视图。