整数3桁+少数1桁の入力
こんな感じでどうでしょう? テキストボックスを使っただけのやり方。
<TextBox x:Name="NumBox"
VerticalAlignment="Top"
InputScope="Number"
TextChanged="NumBox_TextChanged"
DoubleTap="NumBox_DoubleTap"
FontSize="48" Width="200"
TextAlignment="Right"/>
public partial class MainPage : PhoneApplicationPage
{
// コンストラクター
public MainPage()
{
InitializeComponent();
}
//一文字変更するときの値
String txtPrevious = "";
private void NumBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (NumBox.Text != null)
{
String txtNew = NumBox.Text;
double dNew = 0.0;
//文字列を数値に変換
try
{
if( txtNew.EndsWith(".") )
dNew = double.Parse(txtNew+"0");
else
dNew = double.Parse(txtNew);
}
catch
{
//数値に変換できなかったとき
NumBox.Text = txtPrevious;
NumBox.Select(NumBox.Text.Length, 0);
}
//4桁以上、小数点2桁未満は入力させない
if ((dNew >= 1000) || ((int)(dNew * 10) != dNew * 10))
{
//桁を超えた場合は、入力無効で元に戻す。
NumBox.Text = txtPrevious;
NumBox.Select(NumBox.Text.Length, 0);
}
else
{
//入力OK
txtPrevious = NumBox.Text;
}
}
}
private void NumBox_DoubleTap(object sender, System.Windows.Input.GestureEventArgs e)
{
//ダブルタップしたら内容を消す
NumBox.Text = "";
txtPrevious = "";
}
}