|
// Copyright (c) 2010
// by OpenLight Group
// http://openlightgroup.net/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
//
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.ComponentModel;
using System.Windows.Input;
using System.Windows.Controls;
namespace MVVMPopUp
{
public class PopUpViewModel : INotifyPropertyChanged
{
private ChildWindow PopUP;
public PopUpViewModel()
{
// Set the command property
SetPopUpCommand = new DelegateCommand(SetPopUp, CanSetPopUp);
OKButtonCommand = new DelegateCommand(OKButton, CanOKButton);
CancelButtonCommand = new DelegateCommand(CancelButton, CanCancelButton);
}
// Commands
#region SetPopUpCommand
public ICommand SetPopUpCommand { get; set; }
public void SetPopUp(object param)
{
PopUP = (ChildWindow)param;
}
private bool CanSetPopUp(object param)
{
return true;
}
#endregion
#region OKButtonCommand
public ICommand OKButtonCommand { get; set; }
public void OKButton(object param)
{
PopUP.DialogResult = true;
}
private bool CanOKButton(object param)
{
return true;
}
#endregion
#region CancelButtonCommand
public ICommand CancelButtonCommand { get; set; }
public void CancelButton(object param)
{
PopUP.DialogResult = false;
}
private bool CanCancelButton(object param)
{
return true;
}
#endregion
// Properties
#region SelectedPopUpValueProperty
private string _SelectedPopUpValueProperty;
public string SelectedPopUpValueProperty
{
get
{
return this._SelectedPopUpValueProperty;
}
set
{
this._SelectedPopUpValueProperty = value;
this.NotifyPropertyChanged("SelectedPopUpValueProperty");
}
}
#endregion
#region DefaultValueProperty
private string _DefaultValueProperty;
public string DefaultValueProperty
{
get
{
return this._DefaultValueProperty;
}
set
{
this._DefaultValueProperty = value;
this.NotifyPropertyChanged("DefaultValueProperty");
SelectedPopUpValueProperty = this._DefaultValueProperty;
}
}
#endregion
// Utility
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.