MVVM 設計パターンを使い始めたばかりで、行き詰まっています。
アプリケーションが起動するtreeview
と、オブジェクト名のリストが取り込まれます。IsChecked
バインディングをセットアップしましたが、正常に動作します。IsEnabled
バインディングをセットアップしようとしています。
ユーザーが必要なツリービューでアイテムを選択し、3 つのボタンのいずれかをクリックしてアクションを実行するようにします。クリックすると、選択したアイテムがツリービューに残りますが、無効になり、ユーザーはそれらのアイテムに対して別のアクションを実行できなくなります。
アプリケーションで RelayCommand クラスを使用しています。
private ICommandOnExecute _execute;
private ICommandOnCanExecute _canExecute;
public RelayCommand(ICommandOnExecute onExecuteMethod,
ICommandOnCanExecute onCanExecuteMethod)
{
_execute = onExecuteMethod;
_canExecute = onCanExecuteMethod;
}
#region ICommand Members
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public bool CanExecute(object parameter)
{
return _canExecute.Invoke(parameter);
}
public void Execute(object parameter)
{
_execute.Invoke(parameter);
}
#endregion
私のオブジェクトモデルクラスはこれを使用します
private bool _isEnabled;
public bool IsEnabled
{
get { return true; }
set { _isEnabled = value};
}
次に、ボタンメソッド内で
if (interfaceModel.IsChecked)
{
//Does Something
MyObjectName.IsEnabled = false;
}
そして、ここに私のxamlがあります
<CheckBox IsChecked="{Binding IsChecked}" IsEnabled="{Binding IsEnabled, Mode=TwoWay}">
<TextBlock Text="{Binding MyObjectName}" Margin="5,2,1,2" HorizontalAlignment="Left" />
</CheckBox>