[UWP] NumericUpDown - 清除所有值时如何将值设置为0 [英] [UWP] NumericUpDown - How to set the value to 0 when all value is cleared
问题描述
美好的一天,b
$
我有一个WinRTXamlToolkit.Controls,NumericUpDown,我希望在清除所有值时将值设置为0,例如,字段上的值是1234,当我选择all并删除/退格然后失去焦点时,值再次变为1234,当
值为1时,则删除/退格,然后失去焦点值再次为1,我希望它设置为0,那是怎么回事?
谢谢,
NicoTing
Hello NicoTing,
WinRTXamlToolkit中的NumericUpDown 控件是一个预定义的控件,如果我们想要编辑它有一些限制。但是,正如我们可以看到源代码,如果它是可行的,你可以创建自己的源代码(这样你可以有更好的设计)。
无论如何,让我们先看看源代码:
此页面包含所有srouce代码
https://github.com/xyzzer/WinRTXamlToolkit/tree/master/WinRTXamlToolkit/Controls/NumericUpDown
我们可以使用以下属性:
Value =" 30"
最小=" -100"
Maximum =" 2000"所以我们需要的是首先设置这个值。
然后我们可以简单地设置值:
UI代码:
< Grid Background =" {ThemeResource ApplicationPageBackgroundThemeBrush}">
< controls:NumericUpDown LostFocus =" numericcontrol_LostFocus" X:名称= QUOT; numericcontrol"
Width =" 200"
Value =" 30"
最小=" -100"
Maximum =" 2000"
SmallChange =" 0.1"
LargeChange =" 10"的KeyDown = QUOT; numericcontrol_KeyDown"
/>
< / Grid>代码背后:
Double x;
bool flag = false;
private void numericcontrol_LostFocus(object sender,RoutedEventArgs e)
{
if(flag == true)
{
numericcontrol.Value = x;
}
}
private void numericcontrol_KeyDown(object sender,KeyRoutedEventArgs e)
{
if(e.Key == Windows。 System.VirtualKey.Back)
{
x = numericcontrol.Value;
flag = true;
}
}如果这是"0"你的意思是。那么请试一试。
祝你好运,
Barry
Good Day,
I have a WinRTXamlToolkit.Controls, NumericUpDown , I want the value to be set to 0 when all value is cleared , example , the value on the field is 1234 , when I select all and delete/backspace then lost focus , the value becomes 1234 again , and when
the value is 1, then delete/backspace , then lost focus the value is 1 again , I want it to be set to 0 , how is that?
Thanks,
NicoTing
Hello NicoTing,
NumericUpDown control in WinRTXamlToolkit is a predefined control, there are some limitation if we want to edit it. But as we can see source code you are able to create you own if it is posible(in that way you can have a better design).
Anyway, let's see the source code first:
This page contains all the srouce code https://github.com/xyzzer/WinRTXamlToolkit/tree/master/WinRTXamlToolkit/Controls/NumericUpDown
And we can use the following properties:
Value="30" Minimum="-100" Maximum="2000"So what we need is to set this value first.
Then here is a way for us to simply set the value back:
UI Code:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <controls:NumericUpDown LostFocus="numericcontrol_LostFocus" x:Name="numericcontrol" Width="200" Value="30" Minimum="-100" Maximum="2000" SmallChange="0.1" LargeChange="10" KeyDown="numericcontrol_KeyDown" /> </Grid>Code Behind:
Double x; bool flag=false; private void numericcontrol_LostFocus(object sender, RoutedEventArgs e) { if(flag==true) { numericcontrol.Value = x; } } private void numericcontrol_KeyDown(object sender, KeyRoutedEventArgs e) { if(e.Key== Windows.System.VirtualKey.Back) { x= numericcontrol.Value; flag = true; } }If this is "0" you mean. Then please give it a try.
Best regards,
Barry
这篇关于[UWP] NumericUpDown - 清除所有值时如何将值设置为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!