0

I am trying to get the first label and text box to align to the left side of the screen, and the second label and text box to align to the right side of the screen. What am I missing here? The second set of controls will not align to the right.

Thanks in advance!

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <StackPanel Orientation="Horizontal" Grid.Column="0">
            <StackPanel Orientation="Horizontal">
                <Label Content="Active Profile"></Label>
                <TextBox Name="activeProfileName" Width="100" Height="20"></TextBox>
            </StackPanel>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" >
                <Label Content="Create A New Profile"                        
                       HorizontalAlignment="Right"></Label>
                <TextBox Name="activeProfileNamey"
                         Width="100" Height="20"
                         HorizontalAlignment="Right"></TextBox>
            </StackPanel>
        </StackPanel>
    </Grid>
csharpwinphonexaml
  • 3,659
  • 10
  • 32
  • 63
nikotromus
  • 1,015
  • 16
  • 36
  • Possible duplicate of [Aligning controls on both left and right side in a stack panel in WPF](https://stackoverflow.com/questions/12150914/aligning-controls-on-both-left-and-right-side-in-a-stack-panel-in-wpf) – csharpwinphonexaml Feb 01 '18 at 17:42

1 Answers1

0

The outter StackPanel is your problem. Use Grid instead. Your question is actually a duplicate of the Aligning controls on both left and right side in a stack panel in WPF

Here is the code with Grid:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Grid Grid.Column="0">
        <Grid.ColumnDefinitions>
           <ColumnDefinition Width="Auto" />
           <ColumnDefinition Width="*" />
           <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <StackPanel Grid.Column="0" Orientation="Horizontal">
                <Label Content="Active Profile"></Label>
                <TextBox Name="activeProfileName" Width="100" Height="20"></TextBox>
        </StackPanel>
        <StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right" >
            <Label Content="Create A New Profile"                        
                    HorizontalAlignment="Right"></Label>
            <TextBox Name="activeProfileNamey"
                       Width="100" Height="20"
                       HorizontalAlignment="Right"></TextBox>
        </StackPanel>
    </Grid>
</Grid>
zmechanic
  • 1,842
  • 21
  • 27