I’m trying to have 2 controls have the same height. Can I do it with XAML only?
If I did something like <Canvas Height="{Binding Height, ElementName=AnotherControl}" /> it doesn’t actually do anything and the height goes to zero. The Output panel doesn’t complain about any binding errors so AnotherControl.Height really exists. I tried binding to ActualHeight but it doesn’t do anything either.
Anything else I missed?
My guess is that you
AnotherControlis not explicitly given aHeight. Unfortunately, in WinRT (unlike WPF, but the same as Silverlight),ActualWidthandActualHeightare what are known as “calculated properties”. This means that a property changed event doesn’t internally get raised when they change. As a result, binding to them is not reliable, and as you’ve noticed, it wouldn’t quite work.Side note: it may work from time to time, but that is purely because of the timing of the get call the binding framework makes to
ActualHeight.So as it stands, you cannot do it with XAML only. You have to handle the
ActualControl.SizeChangedevent in code-behind, and set theHeighttoAnotherControl.ActualHeightexplicitly.