Grid Column Width - mix *(star), Auto and fill left space

只愿长相守 提交于 2019-12-23 04:36:35

问题


I have a Grid width following Column Definitions:

<Grid.ColumnDefinitions>
        <ColumnDefinition MinWidth="320" MaxWidth="450" Width=".32*"/>
        <ColumnDefinition MinWidth="200" Width="Auto"/>
        <ColumnDefinition MinWidth="200" Width="Auto"/>
        <ColumnDefinition Width="Auto"/> <- (4) should fill all available space
        <ColumnDefinition MinWidth="250" MaxWidth="300" Width=".20*"/>
</Grid.ColumnDefinitions>

The problem is that setting width to Auto on column (4) zeros it's width and last column is next to third one. I'd like to have last column aligned to right edge of app and first three to the left.

I also can't set (4) width to star(*) - obviously it stretches relatively to first and last column.

I've been trying for a while with horizontalalignments but as a result - content is not filling the columns width. I could maybe bind content width to column width or sth like that, but I'm curious whether there is some easy way to achive the (4) column fill all left space.


回答1:


I think you didnt quite undestand the (*) which stands for weighted average.

so for your case.

<Grid.ColumnDefinitions>
     <ColumnDefinition MinWidth="320" MaxWidth="450" Width="3*"/>
     <ColumnDefinition MinWidth="200" Width="Auto"/>
     <ColumnDefinition MinWidth="200" Width="Auto"/>
     <ColumnDefinition Width="5*"/>
     <ColumnDefinition MinWidth="250" MaxWidth="300" Width="2*"/>
 </Grid.ColumnDefinitions> 

if you wish to make the column (4) small reduce the * weightage and increase where you like.

Hope it helps...



来源:https://stackoverflow.com/questions/10244166/grid-column-width-mix-star-auto-and-fill-left-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!