1

すべて、バインドされた完全なモデル、値がコントロールに表示されますが、ボタンのクリックが機能しません...何か提案はありますか? 私が行方不明または間違っていることは何ですか? ありがとう

<Window x:Class="test" Title="test" Height="350" Width="525">
    <StackPanel Name="abc" Orientation="Vertical" DataContext="{Binding Path=EMP, Mode=TwoWay}" Margin="4" Height="153">
        <Label Content="Last Name:" Margin="0,0,4,0"/>
        <TextBox Width="250" Text="{Binding Path=LastName}" Height="20"/>
        <Button Grid.Row="2" Margin="0,0,4,0" Height="40" Width="40" 
                 Command="{Binding Path=SaveCommand}" />
    </StackPanel>
</Window>

class EmployeeVM: ViewModelBase
{
    private bool _Execute = true;
    public EmployeeVM()
    {
        emp = new Model.Employee { FirstName = "abc", LastName = "xyz" };
    }
    private string sFirstName;
    private string sLastName;
    private Model.Employee emp;

    public Model.Employee EMP
    {
        get{return emp;}
        set{emp = value;
            OnPropertyChanged("EMP");}
    }
    public string LastName
    {
        get { return sLastName; }
        set 
        { 
            sLastName = value;
            OnPropertyChanged("LastName");
        }
    }

    #region Commands
    private ICommand _SaveCommand;
    public ICommand SaveCommand
    {
        get
        {
            return _SaveCommand = new CommandHandler(Save, _Execute);
        }
    }
    #endregion

    private void Save(object param)
    {
        ObservableCollection<Model.Employee> newIM = new ObservableCollection<Model.Employee>();
        foreach(Model.Employee e in newIM)
        {
            string a = e.FirstName;
            string b = e.LastName;
        }
    }
}


public class CommandHandler : ICommand
{
    Action<object> _act;
    bool _canExecute;

    public CommandHandler(Action<object> act, bool canExecute)
    {
        _act = act;
        _canExecute = canExecute;
    }

    public bool CanExecute(object parameter)
    {
        return _canExecute;
    }

    public event EventHandler CanExecuteChanged;

    public void Execute(object parameter)
    {
        _act(parameter);
    }
}
4

3 に答える 3