Click here to Skip to main content
15,920,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to proper vertical align the items at the groupbox frame without using margin and padding. The result should look like this picture: http://up.picr.de/17284729tf.png[^] I doun't like to count the pixels. When I'm using
C#
VerticalAlignment="Center"
it centers depending at the window frame. Is there a way to do this?


C#
<UserControl x:Class="Automation.View.ControlWindow"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             Height="Auto" Width="Auto">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <GroupBox Grid.ColumnSpan="2">
            <GroupBox.Header>Control</GroupBox.Header>
        </GroupBox>
        <StackPanel Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Left">
            <Label  Content="Cycle count:" VerticalAlignment="Center"></Label>
            <TextBox x:Name="cycleCount"  Width="25" Height="24" TextAlignment="Center" VerticalAlignment="Center">1</TextBox>
            <StackPanel Grid.Column="0" VerticalAlignment="Center">
                <Button x:Name="cycleCountUp" Content="▲" VerticalAlignment="Bottom" FontSize="6"/>
                <Button x:Name="cycleCountDown" Content="▼" VerticalAlignment="Top" FontSize="6"/>
            </StackPanel>
        </StackPanel>
        <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right" >
            <Button Width="75" Height="24" Margin="5" Click="Button_Click">Continue</Button>
            <Button Width="75" Height="24" Margin="5">Restart</Button>
        </StackPanel>

    </Grid>
</UserControl>
Posted

Hi matlab22,

You didn't specify any Content for your groupbox. Use a StackPanel as Content-Container then add your sub-stackpanels

XML
<groupbox grid.columnspan="2">
     <groupbox.header>Control</groupbox.header>
     <stackpanel>
         <stackpanel grid.column="0" orientation="Horizontal" horizontalalignment="Left"></stackpanel></stackpanel></groupbox>


btw. nothing wrong to set the margin - maybe through a style? And you are not counting pixels but "device units" ;-)

If you don't understand what I mean or need further help, feel free to ask..

Kind regards

Johannes
 
Share this answer
 
Thx i missed this :S

C#
<grid>
    <groupbox>
        <groupbox.header>Control</groupbox.header>
        <grid>

            <grid.columndefinitions>
                <columndefinition width="Auto" />
                <columndefinition width="*" />
            </grid.columndefinitions>

            <stackpanel grid.column="0" orientation="Horizontal" horizontalalignment="Left">
                <Label  Content="Cycle count:" VerticalAlignment="Center"></Label>
                <textbox x:name="cycleCount" width="25" height="24" textalignment="Center" verticalalignment="Center" xmlns:x="#unknown">1</textbox>
                <stackpanel verticalalignment="Center">
                    <Button x:Name="cycleCountUp" Content="▲" VerticalAlignment="Bottom" FontSize="6"/>
                    <Button x:Name="cycleCountDown" Content="▼" VerticalAlignment="Top" FontSize="6"/>
                </stackpanel>
            </stackpanel>

            <stackpanel grid.column="1" orientation="Horizontal" horizontalalignment="Right">
                <Button x:Name="continue_pause"  Width="75" Margin="5" Click="continue_pause_Click">Continue</Button>
                <Button x:Name="restart_stop" Width="75" Margin="5" Click="restart_stop_Click">Restart</Button>
            </stackpanel>

        </grid>
    </groupbox>
</grid>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900