Rev 2364 |
Blame |
Last modification |
View Log
| RSS feed
/*
* Copyright (c) 2008, Andrzej Rusztowicz (ekus.net)
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* 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.
* 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.
* 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.
*/
/*
* Added by Michele Cattafesta (mesta-automation.com) 29/2/2011
* The code has been totally rewritten to create a control that can be modified more easy even without knowing the MVVM pattern.
* If you need to check the original source code you can download it here: http://wosk.codeplex.com/
*/
using System;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;
namespace KeyPad
{
/// <summary>
/// Logica di interazione per MainWindow.xaml
/// </summary>
public partial class Keypad
: Window,INotifyPropertyChanged
{
private string _result
;
int length
= 0;
double min
= 0, max
= 0;
#region Public Properties
public double MIN
{
get { return min
; }
set { min
= value; }
}
public double MAX
{
get { return max
; }
set { max
= value; }
}
public int LENGTH
{
get { return length
; }
set { length
= value; }
}
public string Result
{
get { return _result
; }
set { _result
= value; this.OnPropertyChanged("Result"); }
}
public void disableDecimal
()
{
gDecimal
.Visibility = Visibility
.Hidden;
}
#endregion
public Keypad
(Window owner
)
{
InitializeComponent
();
this.Owner = owner
;
this.DataContext = this;
}
private void button_Click
(object sender, RoutedEventArgs e
)
{
Button button
= sender
as Button
;
switch (button
.CommandParameter.ToString())
{
case "Clear":
Result
= "";
break;
case "ESC":
this.DialogResult = false;
break;
case "RETURN":
double result1
;
if (Double.TryParse(Result,
out result1
))
if (result1
<= max
&& result1
>= min
&& Result
.Length <= length
)
this.DialogResult = true;
break;
case "BACK":
if (Result
.Length > 0)
Result
= Result
.Remove(Result
.Length - 1);
break;
default:
string tmp
= Result
+ button
.Content.ToString();
double result
;
// if (Double.TryParse(tmp,System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.CreateSpecificCulture("en-GB"),out result))
if (Double.TryParse(tmp,
out result
))
{
if (result
<= max
&& tmp
.Length <= length
)
Result
+= button
.Content.ToString();
}
break;
}
}
#region INotifyPropertyChanged members
public event PropertyChangedEventHandler PropertyChanged
;
private void OnPropertyChanged
(String info
)
{
if (PropertyChanged
!= null)
{
PropertyChanged
(this,
new PropertyChangedEventArgs
(info
));
}
}
#endregion
}
}