简体   繁体   中英

Dynamic Grid.ColumnDefinitions in windows phone 8

I need a row with three equal sized columns,

So I declared like,

<Grid.ColumnDefinitions>
    <ColumnDefinition Width="*"></ColumnDefinition>
    <ColumnDefinition Width="*"></ColumnDefinition>
    <ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>

Now, sometimes, any one of my column may be hidden, in that case the remaining two should get equal width. How to achieve this?

You can easily change particular ColumnDefinition 's Width to 0 for hiding corresponding Grid 's column and getting the remaining columns equal width, for example :

//get column definition for the 1st column
var col = myGrid.ColumnDefinitions[0];
//set it's width to 0
col.Width = new GridLength(0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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