UWP--MVVM简单计算器

UWP--MVVM简单计算器_第1张图片

 

namespace LBI.DataBinding
{
    /// <summary>
    /// 可用于自身或导航至 Frame 内部的空白页。
    /// </summary>
    public sealed partial class DataBinding2 : Page
    {
        public MainData MainDataViewModel { get; set; }
        public DataBinding2()
        {
            MainDataViewModel = new MainData();

            this.InitializeComponent();
        }

        private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
        {
            MainDataViewModel.Result = MainDataViewModel.Num1 + MainDataViewModel.Num2;
        }
    }

    public class MainData : INotifyPropertyChanged
    {
        private double num1;
        public double Num1
        {
            get { return num1; }
            set
            {
                num1 = value;
                OnPropertyChanged();
            }
        }

        private double num2;
        public double Num2
        {
            get { return num2; }
            set
            {
                num2 = value;
                OnPropertyChanged();
            }
        }

        private double result;
        public double Result
        {
            get { return result; }
            set
            {
                result = value;
                OnPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}

 

你可能感兴趣的:(UWP--MVVM简单计算器)