简体   繁体   English

WPF 复选框问题

[英]WPF checkbox problem

I have a checkbox in my xaml which is bind to a property and even if the property is false, it is not making the checkbox disabled.我的 xaml 中有一个复选框,它绑定到一个属性,即使该属性为 false,它也不会禁用该复选框。

Here is the xaml:这是 xaml:

<DataGridTemplateColumn Header="checkBox" Width="60">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox  IsChecked="{Binding Path=IsClickable}"/> 
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

viewModel.cs视图模型.cs

    public bool IsClickable
    {
        get { return _isClickable; }
        set { _isClickable = value;
            PropertChanged("IsClickable");}
    }

And I m setting this property at the time of object creation.我在创建 object 时设置此属性。

And im binding the datagrid using itemsource;我使用 itemsource 绑定数据网格;

 Datagrid.ItemsSource = ViewModels;

And I can see that the object collection of viewmodel does have that property populated as false.But is not disabling the checkbox.而且我可以看到视图模型的 object 集合确实将该属性填充为 false。但没有禁用该复选框。

Can some one tell me why please?有人可以告诉我为什么吗?

You're binding the IsChecked property, but if you want to enable/disable the CheckBox , you need to bind the IsEnabled property:您正在绑定IsChecked属性,但如果要启用/禁用CheckBox ,则需要绑定IsEnabled属性:

<CheckBox IsEnabled="{Binding Path=IsClickable}" />

(you will probably need to bind IsChecked to something else, otherwise you won't be able to retrieve the checked state) (您可能需要将IsChecked绑定到其他东西,否则您将无法检索检查状态)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM