我在项目中设计了一个蒙版TextBox
来输入时间格式数字(使用像00:00:00
这样的冒号),它适用于物理键盘,但遗憾的是没有使用触摸屏的数字键盘!
有人有什么建议如何解决这个问题?
这是XAML代码:
<Page
x:Class="test.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:test"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup- compatibility/2006"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
mc:Ignorable="d" Width="800" Height="480">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBox
controls:TextBoxMask.CustomMask="5:[0-5]"
controls:TextBoxMask.Mask="5:59:59"
Name="Textbox"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Width="200" Margin="442,166,158,282"/>
<Button x:Name="button11" Content="1" HorizontalAlignment="Left" Margin="130,122,0,0" VerticalAlignment="Top" Width="45" Height="45" Foreground="#FFA8A8A8" FontSize="24" FontWeight="Bold" BorderThickness="1" ClickMode="Press" BorderBrush="#FFC9C9C9" Tapped="button11_Tapped">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE6E6E6" Offset="0.47"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="button12" Content="2" HorizontalAlignment="Left" Margin="186,122,0,0" VerticalAlignment="Top" Width="45" Height="45" Foreground="#FFA8A8A8" FontSize="24" FontWeight="Bold" BorderThickness="1" ClickMode="Press" BorderBrush="#FFC9C9C9">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE6E6E6" Offset="0.47"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="button13" Content="3" HorizontalAlignment="Left" Margin="242,122,0,0" VerticalAlignment="Top" Width="45" Height="45" Foreground="#FFA8A8A8" FontSize="24" FontWeight="Bold" BorderThickness="1" ClickMode="Press" BorderBrush="#FFC9C9C9">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE6E6E6" Offset="0.47"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="button14" Content="4" HorizontalAlignment="Left" Margin="130,178,0,0" VerticalAlignment="Top" Width="45" Height="45" Foreground="#FFA8A8A8" FontSize="24" FontWeight="Bold" BorderThickness="1" ClickMode="Press" BorderBrush="#FFC9C9C9">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE6E6E6" Offset="0.47"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="button15" Content="5" HorizontalAlignment="Left" Margin="186,178,0,0" VerticalAlignment="Top" Width="45" Height="45" Foreground="#FFA8A8A8" FontSize="24" FontWeight="Bold" BorderThickness="1" ClickMode="Press" BorderBrush="#FFC9C9C9" Tapped="button11_Tapped">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE6E6E6" Offset="0.47"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="button16" Content="6" HorizontalAlignment="Left" Margin="242,178,0,0" VerticalAlignment="Top" Width="45" Height="45" Foreground="#FFA8A8A8" FontSize="24" FontWeight="Bold" BorderThickness="1" ClickMode="Press" BorderBrush="#FFC9C9C9">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE6E6E6" Offset="0.47"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="button17" Content="7" HorizontalAlignment="Left" Margin="130,234,0,0" VerticalAlignment="Top" Width="45" Height="45" Foreground="#FFA8A8A8" FontSize="24" FontWeight="Bold" BorderThickness="1" ClickMode="Press" BorderBrush="#FFC9C9C9">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE6E6E6" Offset="0.47"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="button18" Content="8" HorizontalAlignment="Left" Margin="186,234,0,0" VerticalAlignment="Top" Width="45" Height="45" Foreground="#FFA8A8A8" FontSize="24" FontWeight="Bold" BorderThickness="1" ClickMode="Press" BorderBrush="#FFC9C9C9">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE6E6E6" Offset="0.47"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="button19" Content="9" HorizontalAlignment="Left" Margin="242,234,0,0" VerticalAlignment="Top" Width="45" Height="45" Foreground="#FFA8A8A8" FontSize="24" FontWeight="Bold" BorderThickness="1" ClickMode="Press" BorderBrush="#FFC9C9C9">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE6E6E6" Offset="0.47"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="button20" Content="0" HorizontalAlignment="Left" Margin="186,290,0,0" VerticalAlignment="Top" Width="45" Height="45" Foreground="#FFA8A8A8" FontSize="24" FontWeight="Bold" BorderThickness="1" ClickMode="Press" BorderBrush="#FFC9C9C9">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE6E6E6" Offset="0.47"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="button_delete11" Content="" HorizontalAlignment="Left" Margin="242,290,0,0" VerticalAlignment="Top" Width="45" Height="45" Foreground="#FFA8A8A8" FontSize="16" BorderThickness="1" ClickMode="Press" BorderBrush="#FFC9C9C9" FontFamily="Segoe MDL2 Assets">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE6E6E6" Offset="0.47"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="button_accept11" Content="" HorizontalAlignment="Left" Margin="298,122,0,0" VerticalAlignment="Top" Width="45" Height="213" Foreground="White" FontSize="20" BorderThickness="0" ClickMode="Press" BorderBrush="{x:Null}" FontFamily="Segoe MDL2 Assets" FontWeight="Bold">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF6CC98A" Offset="1"/>
<GradientStop Color="#FFA2FFC1"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Button x:Name="button_cancel11" Content="" HorizontalAlignment="Left" Margin="130,290,0,0" VerticalAlignment="Top" Width="45" Height="45" Foreground="White" FontSize="18" BorderThickness="0" BorderBrush="{x:Null}" ClickMode="Press" FontFamily="Segoe MDL2 Assets">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFF75959" Offset="1"/>
<GradientStop Color="#FFFF9E9E"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<TextBox
x:Name="Textbox_Copy"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Width="200" Margin="442,274,158,174"/>
</Grid>
</Page>
这就是背后的代码:
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void button11_Tapped(object sender, TappedRoutedEventArgs e)
{
Button Btn = (Button)sender;
Textbox_Copy.Text = Textbox_Copy.Text + Btn.Content;
}
}
答案 0 :(得分:0)
我以前遇到过这个问题。由于某些事件被处理,发生此问题。使用任何工具(如xaml spy)触摸您设置的文本框时,检查是否处理了任何事件