views:

104

answers:

3

Hi,

I am trying to get the render size of a region via the region manager. The reason for this is each time I add a view to the region I want to make sure it will visually fit, I can get the dimensions of the view I am about to add but I am struggling to find a way of getting the height of the region I am about to add to.

Obviously I want to stay away from the view behind code and accessing the UIElement for the region directly.

Any ideas?

Thanks for your time

A: 

You can use

_regionManager.Regions[regionName].Views.ElementAtOrDefault(0);

to get the current view of the region you want to use. Then you can check the DesiredSize property of that view to see what the probable width and height is of that region. I think this should work in normal usage.

The thing is there always needs to be a view in that region. If there isn't you might want to use a dummy view or so.

RonaldV
Thanks, thats pretty much what I needed, for some reason I don't have the ElementAtOrDefault method available.What I did was each time a new view is created, listen for its loaded event and then work out the size of the added view if its the first one to be added
Suiva
Which actually doesn't work looking it cause I can only get the size of the view to be added still, not the full region area..
Suiva
ElementAtOrDefault is a linq extention method. If you add "using System.Linq;" to your usings, this should work.
RonaldV
This is incorrect. This shows you information about the Views that have been added to the region, not the size of the region itself.
Anderson Imes
There is no other way to get the size of that region without actually straight out checking it. The DesiredSize of the View is the probable size of the region. I never said it was the actual size of the region. There is no way you would know.
RonaldV
A: 

I'd recommend against trying to do this at all. Instead, I would focus on making the region adaptable to being overfilled (automatic resizing, scrolling, tabs, etc).

There's a lot of unpredictable things that can happen here. For example, there are some controls whose views are determined by their container. The true size of the view that you want to add to the region will not be known until it's actually added to the region, so making this decision will be non-trivial.

I know this doesn't directly answer your question, but hopefully it will be helpful regardless.

Anderson Imes
A: 

Thanks guys, yeah that makes sense, will need to look more into adapting the region I guess. We need it to somehow give feedback when you try to add a view to it that will cause it to overflow the regions height and then decide what to do with that view at a later stage

Suiva