如何引用XAML中的另一个控件?[副本]

iszxjhcz  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(79)

此问题已在此处有答案

WPF: Binding the height of a component to another's(2个答案)
5天前关闭。
我在一个基于XAML文件的C# WPF应用程序中工作。
我有一个标签,叫做“Label_Productnaam”。
我想创建另一个控件(ComboBox),具有相同的高度。
因此我尝试这样的东西:

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

然而,这似乎不起作用。
在XAML中,最简单的方法是什么,说明我的组合框的高度必须与引用的标签的高度相同?

roqulrg3

roqulrg31#

您需要绑定到属性,然后按名称指定其他元素。它将是:

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

相关问题