Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i've an image in a grid in the user control. i've set alignments of the image as stretch. so width and height of the image are set automatically. at the beginning of application i need to know the dimensions of image, but they're NaN and i can't know what values are really assigned to them.

what can i do?

thx
Posted
Comments
Sergey Alexandrovich Kryukov 5-Mar-12 14:00pm    
Where is at the beginning of the application? It could be to early. You need to get it after rendering is complete.
Could you show some code sample and explain your intended use of these dimensions?
--SA
ilostmyid2 6-Mar-12 1:18am    
hithank u for replying.
it has not to be so early. i found that when LayoutUpdated is raised, the image dimensions are available in its ActualWidth and ActualHeight or in its RenderSize. but now there's another problem. how can i access image1 in xaml? the view model needs the dimensions and i instantiate the view model in the xaml. but i can't access the controls in xaml. if i handle the LayoutUpdated event in the code-behind to access image1, this time i have no access to view model.
how can i resolve this problem?
thx

1 solution

The problem is that the ActualWidth and ActualHeight properties are not dependency properties so you will need to created your own that can be bound to on the view model.

Alternatively, Create your own event on the user control that hosts the image, and on the layout updated method, if the previous image size is different from the current size, raise the new image size event.

This can then be listened for in the viewmodel as an ICommand, or some such implementation.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900