Reputation:

want to get a UIElement's Size

I want to get a UIElement's Size, but when I use the DesiredSize or RenderSize property, it always return {0,0}. Could anyone help me?

Upvotes: 1

Views: 1877

Answers (2)

Carlos G.
Carlos G.

Reputation: 4634

Your problem happens because while inside the constructor, you do not have rendered elements. The elements are initialized yes, but they have not been rendered yet, therefore the value returned when you call ActualHeight or ActualWidth is 0 and Height and Width is NaN (Not a Number).

If you ask for the same information after the constructor has finished (for example during the Loaded event for the Window) you will receive that information.

Upvotes: 0

AndrewS
AndrewS

Reputation: 3500

Take a look at the element's ActualWidth and ActualHeight properties. They'll only have values after the element has been rendered.

Upvotes: 2

Related Questions