Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用文本框UWP输入货币_C#_Uwp_Textbox - Fatal编程技术网

C# 如何使用文本框UWP输入货币

C# 如何使用文本框UWP输入货币,c#,uwp,textbox,C#,Uwp,Textbox,我有一个限定为小数的文本框?这是类的一部分: <TextBox PlaceholderText="Fee" Text="{x:Bind ClassObject.Fee, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> 但是,这仍然允许我输入字母字符,并且不会更新类中的十进制值 我应该如何处理十进制的输入?是否粘贴到文本框中?不确定这是否是您要查找的内容,但此代码只允许数字/数字,并防止粘贴到文本框中 XAML: 这就是如何在

我有一个限定为小数的文本框?这是类的一部分:

<TextBox PlaceholderText="Fee" Text="{x:Bind ClassObject.Fee, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
但是,这仍然允许我输入字母字符,并且不会更新类中的十进制值


我应该如何处理十进制的输入?是否粘贴到文本框中?

不确定这是否是您要查找的内容,但此代码只允许数字/数字,并防止粘贴到文本框中

XAML:


这就是如何在WPF中实现它。我希望在UWP中也是如此。
<TextBox PreviewTextInput="OnlyAllowNumbers" CommandManager.PreviewExecuted="PreventPasteIntoTextbox"
</TextBox>
  private void OnlyAllowNumbers(object sender, TextCompositionEventArgs e)
        {
            Regex regex = new Regex("[^0-9]+");
            e.Handled = regex.IsMatch(e.Text);
            regex = null; //optional
            GC.Collect(); //optional
        }

        private void PreventPasteIntoTextbox(object sender, ExecutedRoutedEventArgs e)
        {
            if (e.Command == ApplicationCommands.Copy ||
                e.Command == ApplicationCommands.Cut ||
                e.Command == ApplicationCommands.Paste)
            {
                e.Handled = true;
            }
        }