C# ComboBoxItem上的绑定IsEnabled无效

C# ComboBoxItem上的绑定IsEnabled无效,c#,xaml,windows-8,windows-runtime,C#,Xaml,Windows 8,Windows Runtime,我有这个模型: public class Option : BindableBase { private bool _enabled; public bool Enabled { get { return _enabled; } set { SetProperty(ref _enabled, value); } }

我有这个模型:

public class Option : BindableBase
{
    private bool _enabled;
    public bool Enabled
    {
        get
        {
            return _enabled;
        }
        set
        {
            SetProperty(ref _enabled, value);
        }
    }

    private string _value;
    public string Value
    {
        get
        {
            return _value;
        }
        set
        {
            SetProperty(ref _value, value);
        }
    }
}
在我的viewmodel中,我得到了一个类型为
observetecollection
的列表
Options

我使用这段XAML代码:

<ComboBox Width="200"
          ItemsSource="{Binding Options}">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Value}"/>
                <TextBlock Text="{Binding Enabled}"/>
            </StackPanel>
        </DataTemplate>
     </ComboBox.ItemTemplate>
     <ComboBox.ItemContainerStyle>
         <Style TargetType="ComboBoxItem">
             <Setter Property="IsEnabled" Value="{Binding Enabled}"/>
         </Style>
     </ComboBox.ItemContainerStyle>
 </ComboBox>
 <Setter Property="IsEnabled" Value="false"/>

这些选项实际上已被禁用(我无法选择任何选项),但我想使用一些绑定。有人能解释一下我做错了什么吗?

也许你需要改用path。您可以尝试以下方法:

<Setter Property="IsEnabled" Value="{Binding Path=Enabled}"/>


您要在ComboBoxItem的内容上设置IsEnabled,而您需要在ComboxItem本身上设置IsEnabled。您需要在ItemContainerStyle中设置绑定。不过,我不确定样式设置程序是否支持绑定。如果没有,那么您可能需要使用变通方法来设置绑定。

没有,不幸的是,这没有起到作用,但要感谢您的想法。可能重复的问题可能会导致相同的答案,但这是一个不同的问题,因此有更多的问题有助于更容易找到答案。