我有一個Menu
與MenuItem
s綁定到RegionType
枚舉。
的MenuItems應該有複選標記,我想結合IsChecked
一些ObservableCollection<bool>
(VisibleRegions
):在XAML中爲MenuItem設置源
<ObjectDataProvider x:Key="enumData" MethodName="GetValues" ObjectType="{x:Type System:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="target:RegionType"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
和菜單本身:
<Menu>
<MenuItem Header="Choose item" ItemsSource="{Binding Source={StaticResource enumData}}">
<MenuItem.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="IsCheckable" Value="True"/>
<Setter Property="IsChecked" Value="{Binding VisibleRegions, Mode=TwoWay}"/>
<Setter Property="StaysOpenOnClick" Value="True"/>
</Style>
</MenuItem.ItemContainerStyle>
</MenuItem>
</Menu>
VS輸出告訴我,在運行時:
System.Windows.Data Error: 40 : BindingExpression path error: 'VisibleRegions' property not found on 'object' ''RegionType' (HashCode=0)'. BindingExpression:Path=VisibleRegions; DataItem='RegionType' (HashCode=0); target element is 'MenuItem' (Name=''); target property is 'IsChecked' (type 'Boolean')
消息非常清楚,但是如何糾正這個xaml作品?