简体   繁体   English

WPF DataGrid无法重现WindowsForms DataGrid的大小调整行为

[英]WPF DataGrid can't reproduce WindowsForms datagrid resizing behaviour

I'm looking over the web to reproduce a behaviour that I used almost every time in windows forms: 我正在网上浏览以重现我几乎每次都在Windows窗体中使用的行为:

Columns resize to allow content to fit, if there isn't enough space a scrollbar appear. 列会调整大小以适合内容,如果没有足够的空间,则会显示滚动条。 If I, for example, maximize the window which will allow me to have more space than what is required, the columns resize to fill all that space. 例如,如果我将窗口最大化,这将使我拥有比所需空间更多的空间,则列的大小将进行调整以填充所有这些空间。

How to achieve this? 如何实现呢? Is this possible? 这可能吗?

Use star Width 使用星宽

 <ColumnDefinition Width="1*"/>
 <ColumnDefinition Width="1*"/>

You can set the priority with the number. 您可以使用数字设置优先级。

 <ColumnDefinition Width="3*"/>
 <ColumnDefinition Width="1*"/>

the first column is 3 times the second one. 第一列是第二列的3倍。

如果不通过代码,这是不可能的,我以数千种方式对其进行了测试,而且如果不通过C#代码,就找不到解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM