Microsoft Developer Network > Domovská stránka fór > Windows Presentation Foundation (WPF) > How can I get a button to dock to the right side?
Odeslat dotazOdeslat dotaz
 

OdpovědětHow can I get a button to dock to the right side?

  • 4. listopadu 2009 16:25B. Clay Shannon Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     

    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

Odpovědi

  • 4. listopadu 2009 16:48Mariano O. Rodriguez Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     OdpovědětObsahuje kód
    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/
  • 4. listopadu 2009 17:21dmikon Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     Odpovědět
    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>

Všechny reakce

  • 4. listopadu 2009 16:37wjousts Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     
    Use a DockPanel
  • 4. listopadu 2009 16:44B. Clay Shannon Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     
    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
  • 4. listopadu 2009 16:48Mariano O. Rodriguez Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     OdpovědětObsahuje kód
    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/
  • 4. listopadu 2009 16:48B. Clay Shannon Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     
    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
  • 4. listopadu 2009 17:21dmikon Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     Odpovědět
    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>

  • 5. listopadu 2009 8:17DutchMarcel Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     Obsahuje kód
    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/