У меня есть проект WFP, и я использую шаблон MVVM.У меня есть элемент управления AddressView, который я использовал в CustomerView UserControl.
<my:AddressVeiw Width="340" DataContext="AddressViewModel"/>
Мой AddressVeiw userControl имеет AddressViewModel, а CustomerView имеет CustomerViewModel
код для CustomerViewModel
public DelegateCommand<object> SaveCommand { get; set; }
private string firstName;
public string FirstName
{
get { return firstName; }
set {
firstName = value;
RaisePropertyChanged("FirstName");
SaveCommand.RaiseCanExecuteChanged();
}
}
private string lastName;
public string LastName
{
get { return lastName; }
set {
lastName = value;
RaisePropertyChanged("LastName");
SaveCommand.RaiseCanExecuteChanged();
}
}
private AddressViewModel addressViewModel;
public AddressViewModel AddressViewModel
{
get { return addressViewModel; }
set { addressViewModel = value; }
}
private string middleName;
public string Middlename
{
get { return middleName; }
set
{
middleName = value;
RaisePropertyChanged("MiddleName");
SaveCommand.RaiseCanExecuteChanged();
}
}
private string fullName;
public string FullName
{
get { return fullName; }
set {
fullName = value;
RaisePropertyChanged("FullName");
}
}
private void InitializeCommands()
{
SaveCommand = new DelegateCommand<object>(OnSaveCommand, CanSaveExcute);
}
private bool CanSaveExcute(object obj)
{
if (string.IsNullOrEmpty(firstName) ||string.IsNullOrEmpty(lastName))
return false;
return true;
}
private void OnSaveCommand(object obj)
{
FullName = FirstName + " " + LastName;
}
}
Код для AddressViewModel
private ObservableCollection<Country> countryList = new ObservableCollection<Country>();
public ObservableCollection<Country> CountryList
{
get { return countryList; }
set { countryList = value; }
}
public DelegateCommand<object> SaveCommand { get; set; }
private void Load()
{
try
{
CountryList = (new CountryRepository().GetAll());
}
catch (Exception ex)
{
OnSetStatusBarText("Error: " + ex.Message.ToString());
}
}
private void OnSetStatusBarText(string message)
{
var evt = eventAgg.GetEvent<StatusBarMessageEvent>();
evt.Publish(message);
}
private void InitializeCommands()
{
SaveCommand = new DelegateCommand<object>(OnSaveCommand, CanSaveExcute);
}
private bool CanSaveExcute(object obj)
{
return true;
}
private void OnSaveCommand(object obj)
{
}
Как я могу подключить свою AdddressViewModel к моему AddressView, клиент работает нормально ... Что должно бытьсделано для решения этой проблемы?Спасибо