[英]wpf binding to another control property
so i have this usercontrol : 所以我有这个用户控件:
<UserControl x:Class="Client.SpectrumSpace"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:my="clr-namespace:Client"
mc:Ignorable="d" d:DesignHeight="150" d:DesignWidth="350">
<Canvas>
<Rectangle Width="350" Height="150" Fill="Transparent" Stroke="White" StrokeThickness="1">
<Rectangle.ContextMenu>
<ContextMenu Name="contextMenu">
<MenuItem Name="ctxItem1" Header="AntennaName"
IsEnabled="{Binding MainWindow.availeableAntennas[0]}"/>
</ContextMenu>
</Rectangle.ContextMenu>
</Rectangle>
</Canvas>
</UserControl>
and as you can see im trying to bind the MainWindow.availableAntennas[0] property to the MenuItem.IsEnabled property 如您所见,我正在尝试将MainWindow.availableAntennas [0]属性绑定到MenuItem.IsEnabled属性
this is how i declared the array on MainWindow class: 这就是我在MainWindow类上声明数组的方式:
public bool[] availableAntennas = new bool[9];
my problem is that the IsEnabled property is always true and yes i double checked the availeableAntennas[0] is false, so what am i doing wrong here? 我的问题是IsEnabled属性始终为true,是的,我再次检查了availeableAntennas [0]为false,那么我在这里做错了什么?
You should use "RelativeSource"
of the binding expression. 您应该使用绑定表达式的"RelativeSource"
。
Cheers 干杯
To me, it looks like it could be a few things or all of them: 在我看来,可能是其中的一些或全部:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.