WPF中从绑定ItemSource有TwoWay的方法,也就是前台变了,后台绑定的对象也会改变。
但是后台必须要有使用接口INotifyPropertyChanged。
代码如下:
using System.ComponentModel;
namespace My.ViewModelBase
{
public class ViewModelBase: INotifyPropertyChanged
{
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
public void OnPropertyChanged(string propertyName)
{
var handler = this.PropertyChanged;
if(handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
ViewModel
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExcelAddIn1.ViewModelBase;
namespace ExcelAddIn1.UserControl.ViewModel
{
public class DayEvents: ViewModelBase.ViewModelBase
{
private string _startTime;
public string StartTime
{
get
{