Friday, August 3, 2012

Make GridColumns align in two different Grids in WPF XAML

In XAML UI, some times we want to make GridColumn Width synchronized with other GridColumns in other Grids.

WPF provided a property called  SharedSizeGroup  which allows sizing properties shared between ColumnDefinition or RowDefinition.

And remeber to set  Grid.IsSharedSizeScope="True".


However , when we want one column take up all the available space, like the example above. You will find out that even you write Width="*" still doesn't work as SharedSizeGroup will make it as short as possible.

My solution is , Shared all the columns size except the one contain TextBox.


            <Grid  Grid.IsSharedSizeScope="True">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
                <Grid Name="Grid1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto" SharedSizeGroup="a" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="auto" SharedSizeGroup="c"/>
                        <ColumnDefinition Width="auto"  SharedSizeGroup="d"/>
                    </Grid.ColumnDefinitions>
                 ....
                </Grid>
                <Grid Name="Grid2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto" SharedSizeGroup="a" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="auto" SharedSizeGroup="c"/>
                        <ColumnDefinition Width="auto"  SharedSizeGroup="d"/>
                    </Grid.ColumnDefinitions>
                 .........
                </Grid>

2 comments:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru Dot Net Training in Chennai. Nowadays Dot Net has tons of job opportunities on various vertical industry.
    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

    ReplyDelete