【发布时间】:2017-06-07 00:17:03
【问题描述】:
View ConfigRole 有 2 列,Name 和 IsEnabled(checkBox),每行都有按钮 Edit,
配置角色:
** 如果 CheckBox 对 ConfigRole 视图中的一行为 TRUE,当我单击编辑按钮时,我会得到新的 View Button_Lists,它有 2 列 Name_Button 和 IsEnabled(CheckBox)...我为每个 IsEnabled 修改 TRUE 或 FALSe。
**我的 objectif 是:当 IsEnabled ConfigRole 为 FALSE 时,我想让所有 IsEnabled Button_Lists 默认为 FALSE,
按钮列表:
这是我在 Button_Lists 模型中的尝试代码:
// get all of ButtonsList
public ObservableCollection<ButtonRoleMapClass> ButtonList
{
get { return _buttonList; }
set
{
_buttonList = value;
OnPropertyChanged("ButtonList");
}
}
//viewRoleButton: the Name of selected row in ConfigRole
public ButtonListViewModel(ViewRoleMapClass viewRoleButton)
{
//If IsEnabled for row in ConfigRole is FALSE
if (viewRoleButton.IsEnabled==false)
{
ObservableCollection<ButtonRoleMapClass> butsList = new ObservableCollection<ButtonRoleMapClass>();
foreach (ButtonRoleMapClass button in _buttonList)
{
button.IsEnabled = false;
butsList.Add(button);
}
_buttonList = butsList;
}
我想获取 Datagrid 中的所有 CheckBox for View Button_Lists 默认为 FALSE,
我该如何解决?
【问题讨论】:
-
错误是什么?你能把视图的代码也给吗?
-
直接使用 ButtonList = butsList。那么你的 PropertyChanged 应该可以工作了。
-
不,_buttonList 是值;所以 _buttonList = butsList;是正确的
-
您是否在任何地方设置了_buttonList 的值?如果是这样,它的初始值为 null。