我如何获得一个WPF用户控件的可见部分的大小? [英] How do I get the size of the visible part of a WPF usercontrol?

查看:248
本文介绍了我如何获得一个WPF用户控件的可见部分的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户控件,它包含一个标签和一个文本框。这是一个内部的ScrollViewer

I have a usercontrol 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?

编辑:更多的背景信息

我建立一个非常有限的窗体设计器。一切都发生在code。装饰器用于显示当前选择的控制。

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

推荐答案

我会放一个的画布在你的ScrollViewer并将所有画布上的用户控件。如果装饰器,然后画在画布上,你不必担心它画在上面你的ScrollViewer。

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.

您也将有装饰器下的ScrollViewer消失,而不是仅仅止于它的好处,让您的用户知道控制超出ScrollViewer中。这是怎样的设计师都是我所做的和看到的WPF工作取得。

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.

这篇关于我如何获得一个WPF用户控件的可见部分的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆