Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Visibility in a StackPanel

I have a WPF StackPanel that looks like this: (some attributes removed that don'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 starts as "Hidden".

When I double-click on the top label, I swap the visibility:

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

The intent is to hide the label, and make the TextBox appear in its place.

However, because it is a StackPanel, the TextBox takes up vertical space, even when it is not visible. Then, when the TextBox is revealed, it has blank space above it, where the Label was previously visible.

Is there a good way to make the two items essentially be directly on top of each other? so that double-clicking the Label appears to suddenly change into a TextBox?

like image 285
abelenky Avatar asked Mar 07 '11 20:03

abelenky


1 Answers

Use Visibilty.Collapsed instead. It doesn't reserve the whitespace like Visibilty.Hidden does.

like image 146
Dean Kuga Avatar answered Oct 21 '22 13:10

Dean Kuga