Microsoft Developer Network >
Página Inicial dos Fóruns
>
Windows Presentation Foundation (WPF)
>
How can I get a button to dock to the right side?
How can I get a button to dock to the right side?
I have two buttons in a StackPanel*; I want the "Next" button hugging the left, and the "Close" button clinging to the right. How can I elbow the "Close" button to the East side?
*
<StackPanel Orientation="Horizontal" Grid.Row="9">
<Button Name="btnNext" Width="120" Click="btnNext_Click">Next</Button>
<Button Name="btnClose" Width="120" HorizontalAlignment="Right" Click="btnClose_Click">Close</Button>
</StackPanel>
The HorizontalAlignment="Right" doesn't seem to do diddly squat
Writer / Photographer - http://www.feedbooks.com/userbook/3631
Respostas
- Use DockPanel.Dock property:
<DockPanel Grid.Row="9"> <Button Name="btnClose" Width="120" HorizontalAlignment="Right" DockPanel.Dock="Right" Click="btnClose_Click">Close</Button> <Button Name="btnNext" Width="120" Click="btnNext_Click">Next</Button> </DockPanel>
http://weblogs.asp.net/marianor/- Marcado como RespostaB. Clay Shannon quarta-feira, 4 de novembro de 2009 17:40
- Try this:
<DockPanel Grid.Row="9">
<Button Name="btnNext" Width="120" Click="btnNext_Click" HorizontalAlignment="Left">Next</Button>
<Button Name="btnClose" Width="120" Click="btnClose_Click" HorizontalAlignment ="Right" >Close</Button>
</DockPanel>- Marcado como RespostaB. Clay Shannon quarta-feira, 4 de novembro de 2009 17:40
Todas as Respostas
- Use a DockPanel
- OK, I changed the StackPanel to a DockPanel, but still don't see a property I can set to move the Close button to the right...
Writer / Photographer - http://www.feedbooks.com/userbook/3631 - Use DockPanel.Dock property:
<DockPanel Grid.Row="9"> <Button Name="btnClose" Width="120" HorizontalAlignment="Right" DockPanel.Dock="Right" Click="btnClose_Click">Close</Button> <Button Name="btnNext" Width="120" Click="btnNext_Click">Next</Button> </DockPanel>
http://weblogs.asp.net/marianor/- Marcado como RespostaB. Clay Shannon quarta-feira, 4 de novembro de 2009 17:40
- OK, this sort of works (there's still a margin on the right side for some reason -- it's not moving ALL THE WAY to the right):
<DockPanel Grid.Row="9">
<Button Name="btnNext" Width="120" Click="btnNext_Click">Next</Button>
<Button Name="btnClose" Width="120" Click="btnClose_Click" DockPanel.Dock="Right" >Close</Button>
</DockPanel>
Writer / Photographer - http://www.feedbooks.com/userbook/3631 - Try this:
<DockPanel Grid.Row="9">
<Button Name="btnNext" Width="120" Click="btnNext_Click" HorizontalAlignment="Left">Next</Button>
<Button Name="btnClose" Width="120" Click="btnClose_Click" HorizontalAlignment ="Right" >Close</Button>
</DockPanel>- Marcado como RespostaB. Clay Shannon quarta-feira, 4 de novembro de 2009 17:40
- You're not using the DockPanel correctly. With a DockPanel, the order in which you add the buttons is important. Also, by default, the last child that you add to a DockPanel will take all available space that is left. You can disable this by setting the LastChildFill property on the DockPanel to False.This example shows the differences for the LastChildFill property:
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <DockPanel Grid.Row="0"> <!-- LastChildFill="True" by default --> <Button Width="120" DockPanel.Dock="Right">Close</Button> <Button>Next</Button> </DockPanel> <DockPanel Grid.Row="1" LastChildFill="False"> <Button Name="btnClose" Width="120" DockPanel.Dock="Right">Close</Button> <Button Name="btnNext" Width="120" DockPanel.Dock="Right">Next</Button> </DockPanel> </Grid> </Page>
hth,Marcel
http://dutchmarcel.wordpress.com/

