Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Absolute positioning in WPF

Tags:

wpf

I have a long text and show first sentence in a TextBlock. I wish by clicking the TextBlock or a button to show a panel below the TextBlock with full text. I wish this panel be absolutely positioned and be displayed above any other elements, you can do a similar thing in HTML showing and hiding absolutely positioned 'div' element. How to do this in WPF? Thank you for any suggestions.

like image 667
Dmytro Laptin Avatar asked Oct 29 '25 13:10

Dmytro Laptin


1 Answers

AdornerLayer can work, but may be a little complex. Other options include using PopUps or ToolTips -- you should look into those first as your easiest options.

If these all don't work, it'll really depends on what kind of panel you're using. For example, if you're using a Canvas, all you have to do is make sure to set the correct ZIndex on the element.

In order to make this more robust, I'd suggest the following:

<!-- Set Panel.ZIndex="99" when showing hidden area to ensure top placement -->
<Grid>
  <TextBlock>This is my primary bit of text ...</TextBlock>

  <!-- Canvas stays hidden until we want to show the rest of the text -->
  <Canvas Visibility="Hidden">
    <TextBlock Canvas.Bottom="-10">Content goes here</TextBlock>
  </Canvas>
</Grid>
like image 80
Fortes Avatar answered Oct 31 '25 10:10

Fortes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!