user2209075
user2209075

Reputation: 1189

Binding Height of window to Wight and W to H

Height="{Binding Source=Self, Path=Width}"   
Width="627"   

This doesn't work. To begin, Height gets a length of Width, but when I am changing Width, Height doesn't want to change.

What is wrong here?

Upvotes: 0

Views: 87

Answers (2)

Silver Solver
Silver Solver

Reputation: 2320

Height and Width define the size you want your element to be.

During the rendering of your visuals, the available size for your element is calculated in relation to everything else, and the ActualHeight and ActualWidth are updated.

Height and Width do not change as a result of this calculation, but if Height and Width are changed, the ActualHeight and ActualWidth are recalculated.

Change your Binding path to use the ActualWidth and you should end up with a square.

Height="{Binding ActualWidth, RelativeSource={RelativeSource Self}}"

Upvotes: 1

user1064519
user1064519

Reputation: 2190

You should use RelativeSource binding:

Height="{Binding ActualWidth,RelativeSource={RelativeSource Mode=Self}}"

Upvotes: 1

Related Questions