Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Give equal width to controls inside a Stack Panel

I need to have two RadCharts inside a horizontal StackPanel and want both the charts to be of equal width. I don't want to give explicit length to the width of the charts. This can be easily achieved by using a Grid control but my scenario requires a StackPanel.

like image 297
Merin Nakarmi Avatar asked Jun 03 '13 15:06

Merin Nakarmi


2 Answers

Often the documentation is not quickly comprehensible because it is either written in a confusing way or the needed information is hidden among a ton of other information that doesn't help in the particular case. And so, in my opinion, even if it is a "basic thing", it doesn't hurt to give a quick answer (or if one thinks it is too primitive, he/she should just post nothing at all).

        <StackPanel Orientation="Horizontal" Grid.IsSharedSizeScope="True">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="MySizeGroup" />
                </Grid.ColumnDefinitions>
                <Button Height="23" Content="Reset" Padding="5,1" />
            </Grid>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="MySizeGroup" />
                </Grid.ColumnDefinitions>
                <Button Height="23" Content="Set" Padding="5,1" />
            </Grid>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="MySizeGroup" />
                </Grid.ColumnDefinitions>
                <Button Height="23" Content="Import" Padding="5,1" />
            </Grid>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="MySizeGroup" />
                </Grid.ColumnDefinitions>
                <Button Height="23" Content="Export" Padding="5,1" />
            </Grid>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="MySizeGroup" />
                </Grid.ColumnDefinitions>
                <Button Height="23" Content="Create new" Padding="5,1" />
            </Grid>
        </StackPanel>

Hope this helps :)

like image 64
rabejens Avatar answered Nov 02 '22 08:11

rabejens


Put them into individual Grids, use a column with a common SharedSizeGroup and set Grid.IsSharedSizeScope to true on the StackPanel.

like image 39
H.B. Avatar answered Nov 02 '22 07:11

H.B.