tags:

views:

28

answers:

3

The problem?

<UI:PanelBrowser Margin="12,27,12,32"></UI:PanelBrowser>

WPF is ridiculous in that not manually specifying properties (Such as Width and Height) in this case causes them to have the values Doulbe.NaN. The problem is that I need to know this number. I'm not going to manually set a width and height in the XAML because that stops it from resizing.

Given the above piece of XAML (this object is a simple subclass of the Border control), how can I get the values of the Width and Height properties at run-time?

Edit :

Wow, I feel ridiculous. I read about ActualWidth and ActualHeight, but they were consistently returning 0 and 0 for me. The reason is that I was testing for these properties in the constructor of the Framework Element, before they were actually initialized. Hope this helps someone who runs into the same issue and testing fallacies. :)

+4  A: 

Try using the FrameworkElement.ActualWidth and ActualHeight properties, instead.

Reed Copsey
+1  A: 

You can use elements' "ActualWidth" and "ActualHeight" properties to get the values of the width and height when they were drawn.

Umair Ashraf
+1  A: 

The WPF FrameworkElement class provides two DependencyProperties for that purpose: FrameworkElement.ActualWidth and FrameworkElement.ActualHeight will get the rendered width and height at run-time.

naacal