2010-02-04 72 views
0

我有一个复选框,我需要绑定到源中的布尔,并禁用或启用容器。绑定Silverlight UI属性到源

我的来源是为绑定,如下所示,但它不工作:

private bool isMapEditOn = false; 

OnLoadFunction() 
{ 
    //Bindings 
    Binding mapEditBind = new Binding("IsChecked") { Source = isMapEditOn, Mode = BindingMode.TwoWay }; 

    //Bind to check or uncheck the mapEdit Checkbox 
    ChckEditMap.SetBinding(ToggleButton.IsCheckedProperty, mapEditBind); 
    //Bind to disable children (point and area buttons). 
    EditBtnContainer.SetBinding(IsEnabledProperty, mapEditBind); 
} 

当我测试这通过检查,并取消选中该复选框,它不会坛isMapEditOn。

回答

0

最简单的方法是将isMapEditOn包装在属性中。如果你想改变从源头通知你需要执行INotifyPropertyChanged(这里没有显示在实现此接口信息请参见this页。):

private bool _isMapEditOn = false; 

public bool IsMapEditOn 
{ 
    get 
    { 
     return _isMapEditOn; 
    } 
    set 
    { 
     _isMapEditOn = value; 
    } 
} 

OnLoadFunction() 
{ 
    //Bindings 
    Binding mapEditBind = new Binding("IsMapEditOn") { Source = this, Mode = BindingMode.TwoWay }; 

    //Bind to check or uncheck the mapEdit Checkbox 
    ChckEditMap.SetBinding(ToggleButton.IsCheckedProperty, mapEditBind); 
    //Bind to disable children (point and area buttons). 
    EditBtnContainer.SetBinding(IsEnabledProperty, mapEditBind); 
} 
0

尝试使用类型bool?而不是布尔。 IsChecked属性定义为:

public bool? IsChecked { get; set; } 
+0

我改变私人布尔isMapEditOn = FALSE;私人布尔? isMapEditOn = false;如果这就是你所说的话,它就不起作用。 – 2010-02-05 06:24:06