سؤال

This has probably been asked before but I am not sure how to search for it as I haven't found a definite answer.

I am new to WPF (just coming from WinForms) and I want to use an Expander to show and hide a few fields. When the Expander expands, the border underneath it needs to change with it so that it makes room for the expander.

When the expander is retracted, the border goes back into its original size.

Would I have to use the Event from the Expander somehow which tells that the expander is now expanding?

My example The Issue

As you can see from the pictures this is not desirable. This would be however:

Desired result

هل كانت مفيدة؟

المحلول

Here's a really simple example. I've created a grid with two rows.

The first has your expander, and its height is set to Auto, so it'll only take as much room as it needs.

The second has your border; it's height is *, so it'll take as much room as it can.

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Expander Content="hi" Header="bye" />
    <Border Grid.Row="1" BorderThickness="1" BorderBrush="Black" />
</Grid>

Effect:

enter image description here

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top