tags:

views:

48

answers:

3

Hello All,

I have a problem in getting Actual height and Acual width of Image control in WPF. When user selects the image file. I want to resize the selected image based on the dimentions of the image control.

I tried to get the Image.ActualHeight and Image.ActualWidth when window initializes, but I found that both properties of Image control are '0'.

So how to get the Dimentions of the Image control.

Thank you, Harsha

+1  A: 

Off the top of my head, I think you should subscribe to the Load event on the image control, the ActualHeight/Width are not updated until that event fires.

soren.enemaerke
+1  A: 

Hi,

the remarks for FrameworkElement.ActualHeight say that there might be some lag before the property has its real value.

This property is a calculated value based on other height inputs, and the layout system. The value is set by the layout system itself, based on an actual rendering pass, and may therefore lag slightly behind the set value of properties such as Height that are the basis of the input change.

The final size of your control is set by FrameworkElement.Arrange(-Override). You could override the method and just call the base class implementation. Its return value will be the actual size of your Image.

andyp
A: 

The control's ActualSize is set after the "Measure" layout pass (the "Arrange" layout pass sets its location). The other two answers are helpful; the "Arrange" layout pass of the container only happens after its children have been measured, and the load handler of your image control should be called after its first layout pass has completed.

Ed Noepel