开发者

How do I get the size of the visible part of a WPF usercontrol?

开发者 https://www.devze.com 2023-03-08 13:00 出处:网络
I have a usercontr开发者_开发百科ol that consists of a label and a textbox. It\'s inside a scrollviewer.

I have a usercontr开发者_开发百科ol that consists of a label and a textbox. It's inside a scrollviewer.

I'm drawing an adorner on top of it and I need to adjust the size of the adorner to the visible size of the control.

How do I get the visible size of the control?

In the image below the green rectangle is the adorner. As you can see it's being drawn over the scrollbar on the right side.

Is it possible to get the size of the rendered part or will I have to manually go trough the visual tree and calculate it?

edit: more background info

I'm build a very limited form designer. Everything is happening in code. The adorner is used to display the current selected control.

How do I get the size of the visible part of a WPF usercontrol?


I would put a Canvas in your ScrollViewer and place all of your user controls on the Canvas. If the Adorner is then painted on the Canvas you don't have to worry about it drawing over top your ScrollViewer.

You would also have the added benefit of the adorner disappearing under the ScrollViewer, rather than just ending at it, so your users know that the control extends beyond the ScrollViewer. This is how all of the designers I've made and seen made in WPF work.


If you are only worried about clipping the adorner, then you can include an AdornerDecorator in your content. Something like:

<ScrollViewer>
    <AdornerDecorator>
        <!-- Your content here -->
    </AdornerDecorator>
</ScrollViewer>

Or you can include the AdornerDecorator directly in your UserControl.

0

精彩评论

暂无评论...
验证码 换一张
取 消