B
B
BadCats2017-06-19 12:24:05
WPF
BadCats, 2017-06-19 12:24:05

DockPanel issues - alignment not working?

<DockPanel  Width="Auto" Height="Auto">

        <Button DockPanel.Dock="Right" Width="50">dock 2.1</Button>


    </DockPanel>

- in this case, it turns out that the button is in the center and not on the right
, but if you add like this
<DockPanel Name="DP1">

        <Button DockPanel.Dock="Right" Width="50">dock 2.1</Button>
        <Button DockPanel.Dock="Right" Width="50">dock 2.1</Button>



    </DockPanel>

- then the second button will be "magnetized" - correctly, and the first one will be in the center. How to do - so that the first button (I should have one) is immediately on the right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BadCats, 2017-06-19
@BadCats

Add the LastChildFill property:

<DockPanel  LastChildFill="False">
    <Button DockPanel.Dock="Right" Width="50">dock 2.1</Button>
</DockPanel>

O
OlegRV, 2017-06-19
@OlegRV

This happens because there is no element occupying the free space. You can do it in two ways:
either add some kind of container:

<DockPanel Height="Auto">
  <Button DockPanel.Dock="Right" Width="50">dock 2.1</Button>
  <Grid>
      
  </Grid>
</DockPanel>

or set the button to HorizontalAlignment="Right".
The first option is preferable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question