Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Prevent elements in the DockPanel from expanding

I have the following code,
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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading