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?
This Question is very old, but here is my solution. You can use this Code
I've tested it on my Windows / Windows Phone 8.1 Device and it workes great.
As Kshitij Mehta mentioned, binding to ActualHeight and ActualWidth in WinRT isnt reliable. But there is a nice work-around, where you dont have to use the SizeChanged-Event:
Add this class:
Place it in the resources:
And bind to its properties:
My guess is that you
AnotherControl
is not explicitly given aHeight
. Unfortunately, in WinRT (unlike WPF, but the same as Silverlight),ActualWidth
andActualHeight
are 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.SizeChanged
event in code-behind, and set theHeight
toAnotherControl.ActualHeight
explicitly.