Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2357 - 1

2
 
3
/*
4
 * Copyright (c) 2008, Andrzej Rusztowicz (ekus.net)
5
* All rights reserved.
6
 
7
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
8
 
9
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10
 
11
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
12
 
13
* Neither the name of ekus.net nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
14
 
15
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
*/
17
/*
18
 * Added by Michele Cattafesta (mesta-automation.com) 29/2/2011
19
 * The code has been totally rewritten to create a control that can be modified more easy even without knowing the MVVM pattern.
20
 * If you need to check the original source code you can download it here: http://wosk.codeplex.com/
21
 */
22
using System;
23
using System.Windows;
24
using System.Windows.Controls;
25
using System.ComponentModel;
26
 
27
namespace KeyPad
28
{
29
    /// <summary>
30
    /// Logica di interazione per MainWindow.xaml
31
    /// </summary>
32
    public partial class Keypad : Window,INotifyPropertyChanged
33
    {
34
        #region Public Properties
35
 
36
        private string _result;
37
        public string Result
38
        {
39
            get { return _result; }
40
            set { _result = value; this.OnPropertyChanged("Result"); }
41
        }
42
 
43
        #endregion
44
 
45
        public Keypad(Window owner)
46
        {
47
            InitializeComponent();
48
            this.Owner = owner;
49
            this.DataContext = this;            
50
        }        
51
 
52
        private void button_Click(object sender, RoutedEventArgs e)
53
        {
54
            Button button = sender as Button;
55
            switch (button.CommandParameter.ToString())
56
            {
57
                case "ESC":
58
                    this.DialogResult = false;
59
                    break;
60
 
61
                case "RETURN":
62
                    this.DialogResult = true;
63
                    break;
64
 
65
                case "BACK":
66
                    if (Result.Length > 0)
67
                        Result = Result.Remove(Result.Length - 1);
68
                    break;
69
 
70
                default:
71
                    Result += button.Content.ToString();
72
                    break;
73
            }  
74
        }    
75
 
76
        #region INotifyPropertyChanged members
77
 
78
        public event PropertyChangedEventHandler PropertyChanged;
79
        private void OnPropertyChanged(String info)
80
        {
81
            if (PropertyChanged != null)
82
            {
83
                PropertyChanged(this, new PropertyChangedEventArgs(info));
84
            }
85
        }
86
 
87
        #endregion
88
 
89
 
90
 
91
    }
92
}