码迷,mamicode.com
首页 > 其他好文 > 详细

MVVM--简单计算器Demo

时间:2016-01-26 12:09:23      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

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));
            }
        }
    }
}

 

MVVM--简单计算器Demo

标签:

原文地址:http://www.cnblogs.com/liubiao/p/5159539.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!