0

On my form, I have a TextBlock element that initially is collapsed. (TextBlock.Visibility = Visibility.Collapsed). When some error occurred, it should be shown. When I use TextBlock.Visibility = Visibility.Show, all the controls that are situated under the TextBlock, are getting down.

Question: How to dock all the elements that are situated under this TextBlock in such a way that in case when the TextBlock is shown, to lift the upper elements?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72

2 Answers2

1

One way to achieve that is through strategic use of the VerticalAlignment property. Consider the following snippet. If this stackpanel is in a container where it has room to grow, it will grow upwards. When you toggle the visibility on the middle textblock, then, it will push the elements above it.

<StackPanel VerticalAlignment="Bottom">
    <TextBlock>I shift upward</TextBlock>
    <TextBlock Visibility="Collapsed">Error message here</TextBlock>
    <TextBlock>I stay put</TextBlock>
</StackPanel>
Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Charles Josephs
  • 1,495
  • 3
  • 14
  • 25
0

I am not sure exactly what your question is, but if you do not want the other controls to move when the TextBlock becomes visible then it should start with Visibility.Hidden.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Doug Ferguson
  • 2,538
  • 2
  • 16
  • 23