Fazer uma PerguntaFazer uma Pergunta
 

RespondidoHow can I get a button to dock to the right side?

  • quarta-feira, 4 de novembro de 2009 16:25B. Clay Shannon Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    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

  • quarta-feira, 4 de novembro de 2009 16:48Mariano O. Rodriguez Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     RespondidoContém Código
    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
    •  
  • quarta-feira, 4 de novembro de 2009 17:21dmikon Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    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

  • quarta-feira, 4 de novembro de 2009 16:37wjousts Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Use a DockPanel
  • quarta-feira, 4 de novembro de 2009 16:44B. Clay Shannon Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    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
  • quarta-feira, 4 de novembro de 2009 16:48Mariano O. Rodriguez Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     RespondidoContém Código
    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
    •  
  • quarta-feira, 4 de novembro de 2009 16:48B. Clay Shannon Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    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
  • quarta-feira, 4 de novembro de 2009 17:21dmikon Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    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
    •  
  • quinta-feira, 5 de novembro de 2009 8:17DutchMarcel Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Contém Código
    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/