IsEnabled绑定到布尔值 [英] IsEnabled binding to a boolean

查看:244
本文介绍了IsEnabled绑定到布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的对话框列表,其中包含一些复选框,我希望有一个确定"按钮,除非用户更改设置,否则该按钮将被禁用.在我看来,我具有将按钮的isEnabled属性绑定到的OkEnabled属性,如果复选框的值更改,它将OkEnabled设置为true,但是由于某些原因,这不会启用按钮.

I have a list a simple dialog box which contains a few checkboxes, I wanted to have an Ok button that would be disabled unless the user changed a setting. In my view I have an OkEnabled property that I was binding the isEnabled property of the button to, if a check box changes its value it sets OkEnabled to true, but for some reason this doesnt enable the button.

public bool OkEnabled
{
    get
    {
        return m_okEnabled;
    }
    set
    {
        m_okEnabled = value;
        OnPropertyChanged("OkEnabled");
    }
}

<Button Content="OK" Style="{StaticResource MyButton}" Height="23" 
        HorizontalAlignment="Left" Margin="20" Name="m_okbutton" 
        VerticalAlignment="Top" Width="75"
        Click="okClick" IsEnabled="{Binding Path=OkEnabled}"/>

由于某些原因,当OkEnabled属性更改状态时,确定"按钮不会更改状态.如果将IsEnabled属性绑定到其中一个复选框,则可以看到该复选框更改时按钮的更改状态.

For some reason the Ok button won't change state when the OkEnabled property changes state. If I bind the IsEnabled property to one of the checkboxes I can see the button change state as the check box changes.

推荐答案

在我看来,我有一个OkEnabled属性

In my view I have an OkEnabled property

默认情况下,绑定是相对于DataContext而非视图的.您是否将视图设置为其自己的DataContext?

By default, bindings are relative to the DataContext, not the view. Did you set the view as its own DataContext ?

这篇关于IsEnabled绑定到布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆