This time my quick tip will be not about the Silverlight, but about WPF.
When you have WPF window, the runtime size of it could be discovered by ActualWidth/ActualHeight properties. In most cases this is enough. But what about the case, when you need to perform some mathematical calculations based on the real size of client area? What is this client area?
Well, the second question is really easy one – the client area is the area available to user defined UI (controls, panes, etc.):
At the screenshot – client area is a pink part of the window.
The client area size could be calculated differently. First, most WPF-oriented method is to get ActuialWidth/ActualHeight from auto-sized top-level panel (in my case from Canvas):
This is very easy way, but what to do with a containers/panels which will auto-size according to child elements and not the Window? For this case there are two additional approaches.
Second approach is to use Win32 API to calculate the available size:
Getting the size:
In this case we will get exactly the same values, like from ActualWidth/ActualHeight of auto-sized controls, but will work always.
The third approach is to calculated the size from Window size minus borders width and window caption height. This will give us estimation based on current theme, but in this case we need to know additional information (like WindowStyle – in my case I’m using “ThreeDBorderWindow”):
The value is estimation, and should be used wisely.
Stay tuned for more…