Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight float content right

I'm trying to get a horizontal StackPanel with some text, and then a button stuck all the way to the right hand side. I tried this:

                <StackPanel Orientation="Horizontal">
                    <TextBlock VerticalAlignment="Center" FontSize="14" Margin="5,0,0,0">Ahoy!</TextBlock>
                    <Button HorizontalAlignment="Right" Width="25" Height="25" Style="{StaticResource buttonGlassOrb}" Background="Red" />
                </StackPanel>

Which doesn't seem to work. Obviously adding a margin to the TextBlock will work, like this:

                <StackPanel Orientation="Horizontal">
                    <TextBlock VerticalAlignment="Center" FontSize="14" Margin="5,0,120,0">Ahoy!</TextBlock>
                    <Button HorizontalAlignment="Right" Width="25" Height="25" Style="{StaticResource buttonGlassOrb}" Background="Red" />
                </StackPanel>

But that's bad for all sorts of reasons. Are there any more natural ways to do this?

like image 502
Adam Rackis Avatar asked Nov 05 '10 15:11

Adam Rackis


1 Answers

Personally, I would use a Grid instead of a StackPanel for this. Just add two columns, one set to size "*" and one to "Auto", and put your TextBlock in column one, Button in Column two:

like image 84
Reed Copsey Avatar answered Oct 05 '22 12:10

Reed Copsey