views:

87

answers:

1

Hi,

is there any way to determine the visible region of a WPF control that is clipped by parent controls (e.g. ScrollViewer, Canvas, or panes)?

Background of my question: we are using the WebBrowser control in our application. Since it is derived from HwndHost, parent controls cannot clip it, i.e. it will overlap parent controls, which does not look nice. Thefore, my idea was to automatically resize the WebBrowser control when it does not fit entirely into the parent controls. Our application is very flexible and therefore it is hard to predict what the hierarchy of parent controls for the WebBrowser control is. Therefore, I would need a method "UIElement.GetVisibleRegion()" that returns a Rect or Geometry with the visible part of the control, in control coordinates.

Many thanks for any helpful suggestions in advance.

+1  A: 

Maybe you could embed the WebBrowser inside a container control (like Border) and handle the SizeChanged event of the container to resize the web browser control to fit. A custom control could be nice if you need to do it more than once.

AndrewS
The size of the WebBrowser control is not changed; it is the size of one of the parent controls that is changed and thereby changes the visible part of the WebBrowser control. If everything in our application were hardcoded, we could react on the SizeChanged event of the parent control. In our application, however, the WebBrowser control can appear anywhere in a control hierarchy and therefore we a more generic approach.
fmunkert
Can't you embed the browser control inside a UserControl which resizes the browser control when its own size changes? You could put the UserControl anywhere in the hierarchy and have it maintain its child web browser control.
AndrewS
We want to avoid to add code to controls higher up in the hierarchy for resizing the WebBrowser control, because the control will be used at many different places in many different situations. Therefore, all the intelligence should be part of a class derived from the WebBrowser control (e.g. customer control).
fmunkert
That is basically what I am saying. UserControl = custom control. However I suggest wrapping the WebBrowser in the UserControl rather than deriving from the WebBrowser control itself.
AndrewS
Hi, I am accepting your answer because it provides a solution for some kinds of applications. For our complex application, it is no viable solution. In the meantime I have talked to MS, and they basically told that there currently is no may to determine a clipping region.
fmunkert