-1

I have the following code where I want to prevent the first two buttons from expanding when the Expander is opened:

<Grid>
    <DockPanel HorizontalAlignment="Left">
        <Button Content="AAAAA" DockPanel.Dock="Top"/>
        <Button Content="AAAAA" DockPanel.Dock="Top"/>
        <Expander>
            <Button Content="AAAAAAAAAA" DockPanel.Dock="Top"/>
        </Expander>
    </DockPanel>
</Grid>

I would appreciate help on how to do this in a clean way.

ouflak
  • 2,458
  • 10
  • 44
  • 49
OrLevi
  • 62
  • 5

1 Answers1

1

This is happening to you because the default value of HorizontalAlignment is Stretch. Therefore, to achieve the result you asked for, you need to do this:

<Grid>
    <DockPanel HorizontalAlignment="Left">
        <Button Content="AAAAA" DockPanel.Dock="Top" HorizontalAlignment="Left"/>
        <Button Content="AAAAA" DockPanel.Dock="Top" HorizontalAlignment="Left"/>
        <Expander>
            <Button Content="AAAAAAAAAA" DockPanel.Dock="Top"/>
        </Expander>
    </DockPanel>
</Grid>
Ohad Cohen
  • 597
  • 4
  • 9