所以我有这个用户控件:
<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>
如您所见,我试图将 MainWindow.availableAntennas[0] 属性绑定到 MenuItem.IsEnabled 属性
这就是我在 MainWindow 类上声明数组的方式:
public bool[] availableAntennas = new bool[9];
我的问题是 IsEnabled 属性始终为真,是的,我仔细检查了可用天线 [0] 是否为假,那么我在这里做错了什么?