Search code examples
c#wpfxamlreferencecontrols

How can I refer to another control in a XAML?


I'm working in a C# WPF application, based on XAML files.

I have a label, called "Label_Productnaam".

I would like to create another control (a ComboBox), having the same height.

Therefore I'm trying something like this:

<Label Content="Productnaam :" Name="Label_Productnaam"></Label>
...
<ComboBox ... Height="{Binding "Label_Productnaam.Height"}"

This, however, seems not to work.

What's the easiest way to say in a XAML that the height of my combobox must be the same as the one of the referred label?


Solution

  • You need to bind to the property, and then specify the other element by name. Here it would be:

    <ComboBox Height="{Binding ActualHeight, ElementName=Label_Productnaam}"/>