Search code examples
wpfxamlwrappanel

WrapPanel with dynamic height childs


I have WrapPanel with 2 columns and as childs I use something like this:

<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition />
    </Grid.RowDefinitions>      

    <Button HorizontalAlignment="Left" 
            Grid.Row="0" x:Name="Button" FontSize="20" Click="ShowTextblock">
        <TextBlock TextWrapping="Wrap" TextDecorations="underline" 
                   TextAlignment="Left">
            ButtonName          
        </TextBlock>
    </Button>

    <TextBlock Grid.Row=1 Visibility="Collapsed">SampleText</TextBlock>
</Grid>

So, idea is when user click button - he can see textblock under this button. Like this:

button button
text button
for button
button button
button button

But as result I have this:

button button
text
for
button
button button

So, how can I do what I want?


Solution

  • Problem was solved with 2 separated StackPanels