Changing Visibility in a StackPanel

I have a WPF StackPanel that looks like this: (some attributes are removed, which doesn't matter)

<StackPanel HorizontalAlignment="Center" Name="PICStack"> <Label Name="PICName" MouseDoubleClick="PICName_MouseDoubleClick" /> <TextBox Name="PICData" Width="120" Visibility="Hidden" /> <Label Name="PICWeight" /> <Label Name="PICARM" /> </StackPanel> 

Note that the TextBox launches as Hidden.

When I double click on the top label, I change the visibility:

 private void PICName_MouseDoubleClick(object sender, MouseButtonEventArgs e) { this.PICData.Visibility = Visibility.Visible; this.PICName.Visibility = Visibility.Hidden; } 

The goal is to hide the label and make the TextBox in place.

However, since this is a StackPanel, the TextBox takes up vertical space, even if it is not displayed. Then, when a TextBox is detected, it has an empty space above it where the label was previously marked.

Is there a good way to make two elements essentially directly on top of each other? so that double-clicking on a shortcut unexpectedly turns into a TextBox?

+7
source share
2 answers

Use Visibilty.Collapsed instead. It does not save spaces like Visibilty.Hidden .

+21
source

You should try Visibility.Collapsed instead of Visibility.Hidden .

+9
source

All Articles