在WPF中,可以使用以下方法实现双向数据绑定:
Mode="TwoWay"来实现。示例代码:
ViewModel类中定义属性:
private string _name;
public string Name
{
    get { return _name; }
    set 
    {
        _name = value;
        OnPropertyChanged(nameof(Name)); //触发属性更改通知
    }
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
XAML中绑定属性:
<TextBox Text="{Binding Name, Mode=TwoWay}" />
示例代码:
ViewModel中定义命令:
private ICommand _updateCommand;
public ICommand UpdateCommand
{
    get
    {
        if (_updateCommand == null)
        {
            _updateCommand = new RelayCommand(UpdateName, CanUpdateName);
        }
        return _updateCommand;
    }
}
private bool CanUpdateName(object parameter)
{
    //根据具体逻辑判断是否可以执行命令
    return true;
}
private void UpdateName(object parameter)
{
    //根据具体逻辑更新Name属性的值
    Name = "New Name";
}
XAML中绑定命令:
<Button Content="Update" Command="{Binding UpdateCommand}" />
这样,当用户点击按钮时,命令会执行,从而更新Name属性的值。