WPF 触摸屏小键盘样式
WPF程序,用于平板时,一些输入数量的地方我们需要弹出小键盘输入,这个键盘可以调系统的,也可以自己写。
分享个我现在用的一个数字键盘界面。

<Window xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors" x:Class="NFMES.UI.Base.NumericKeyBoard"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" Background="#FF333333" Title="NumericKeyBoard" ResizeMode="NoResize"
Height="400" Width="300" Deactivated="Window_Deactivated" FocusManager.FocusedElement="{Binding ElementName=btn}">
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="FontSize" Value="35" />
<Setter Property="Margin" Value="3"/>
</Style>
</Window.Resources>
<Grid FocusManager.FocusedElement="{Binding ElementName=btn}">
<Grid.RowDefinitions>
<RowDefinition Height="0.2*"/>
<RowDefinition Height="0.8*"/>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<dxe:TextEdit x:Name="txtValue" Background="DarkGray" BorderThickness="2" BorderBrush="Black" FontSize="30" HorizontalContentAlignment="Right"/> <Button Grid.Column="1" Click="Button_Click" >
<!--<Button.Background>
<ImageBrush ImageSource="返回2.png" Stretch="Fill"/>
</Button.Background>-->
<Image Source="前进.png" />
</Button> </Grid> <Grid Grid.Row="1" Button.Click="Grid_Click" FocusManager.FocusedElement="{Binding ElementName=btn}"> <Grid.RowDefinitions> <RowDefinition />
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button x:Name="btn" Content="1" />
<Button Content="2" Grid.Row="0" Grid.Column="1"/>
<Button Content="3" Grid.Row="0" Grid.Column="2"/>
<Button Content="4" Grid.Row="1" Grid.Column="0"/>
<Button Content="5" Grid.Row="1" Grid.Column="1"/>
<Button Content="6" Grid.Row="1" Grid.Column="2"/>
<Button Content="7" Grid.Row="2" Grid.Column="0"/>
<Button Content="8" Grid.Row="2" Grid.Column="1"/>
<Button Content="9" Grid.Row="2" Grid.Column="2"/> <Button Content="." Grid.Row="3" Grid.Column="0"/>
<Button Content="0" Grid.Row="3" Grid.Column="1"/>
<Button x:Name="Back" Grid.Row="3" Grid.Column="2">
<!--<Button.Background>
<ImageBrush ImageSource="返回1.png" Stretch="Fill"/>
</Button.Background>-->
<Image Source="返回1.png" />
</Button>
</Grid>
</Grid> </Window>
后台cs文件代码:
using DevExpress.Xpf.Editors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes; namespace NFMES.UI.Base
{
/// <summary>
/// NumericKeyBoard.xaml 的交互逻辑
/// </summary>
public partial class NumericKeyBoard : Window
{
private static SpinEdit _SpinEdit;
private static NumericKeyBoard _NumericKeyBoard;
public NumericKeyBoard(SpinEdit spinEdit)
{
InitializeComponent();
_SpinEdit = spinEdit;
} private void Window_Deactivated(object sender, EventArgs e)
{
// this.Hide();
} private void Grid_Click(object sender, RoutedEventArgs e)
{
try
{ Button btn = e.OriginalSource as Button;
if (btn.Name == "Back")
{
txtValue.Text = txtValue.Text.Substring(, txtValue.Text.Length-);
}
else
{
txtValue.Text += btn.Content;
}
}
catch
{
}
} private void Button_Click(object sender, RoutedEventArgs e)
{
_SpinEdit.Text = (txtValue.Text.Length==?"":txtValue.Text);
this.Close();
}
}
}
当然触摸屏上也可以直接调用系统键盘。
System.Diagnostics.Process.Start(@"C:\Windows\System32\osk.exe");

有时候因为权限问题,不可以直接调用系统盘下面的键盘。我们可以将osk.exe拷贝到程序根目录下再调用。
WPF 触摸屏小键盘样式的更多相关文章
- wpf 触摸屏 button 背景为null的 问题
原文:wpf 触摸屏 button 背景为null的 问题 <!-- button样式--> <Style x:Key="myBtn" TargetType=&q ...
- WPF自定义控件与样式(3)-TextBox & RichTextBox & PasswordBox样式、水印、Label标签、功能扩展
一.前言.预览 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要是对文本 ...
- WPF自定义控件与样式(1)-矢量字体图标(iconfont)
一.图标字体 图标字体在网页开发上运用非常广泛,具体可以网络搜索了解,网页上的运用有很多例子,如Bootstrap.但在C/S程序中使用还不多,字体图标其实就是把矢量图形打包到字体文件里,就像使用一般 ...
- WPF自定义控件与样式(2)-自定义按钮FButton
一.前言.效果图 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 还是先看看效果 ...
- WPF自定义控件与样式(15)-终结篇 & 系列文章索引 & 源码共享
系列文章目录 WPF自定义控件与样式(1)-矢量字体图标(iconfont) WPF自定义控件与样式(2)-自定义按钮FButton WPF自定义控件与样式(3)-TextBox & Ric ...
- WPF自定义控件与样式(4)-CheckBox/RadioButton自定义样式
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: Che ...
- WPF自定义控件与样式(5)-Calendar/DatePicker日期控件自定义样式及扩展
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: 日历控 ...
- WPF自定义控件与样式(6)-ScrollViewer与ListBox自定义样式
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: Scr ...
- WPF自定义控件与样式(7)-列表控件DataGrid与ListView自定义样式
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: Dat ...
随机推荐
- day14(内置函数)
print(list(map(func, lambda x : x)) print(list(filter lambda x : x > len(x))) print(zip(l1,l2,tu) ...
- python学习 day08 (3月13日)----函数
函数 一.定义 def 关键字 函数名(): 函数体 函数 ---- 封装#def 关键字 # #定义后的函数就像变量 不调用是不执行的 # #函数名() ==函数的调用 def code(): ...
- ubuntu新建、删除用户
新建用户名为newuser的用户,并赋予sudo权限 adduser newuser --ingroup sudo 删除用户以及用户目录 deluser -r newuser
- centos7 lvm实例
1.lvm安装 rpm -qa|grep lvm lvm version yum install -y lvm2* 2.磁盘分区 fdisk -l fdisk /dev/xvdb1 #分区结束标记 t ...
- 系统当前时间system.currenttimemillis与new Date().getTime() 区别
system.currenttimemillis //取到毫秒数,并且执行效率高 new Date().getTime()没他精确
- C++STL priority_queue
priority_queue优先级队列 最大值优先级队列(队头是最大值) 最小值优先级队列(队头是最小值) priority_queue<int> q1;//默认定义为最大值优先级队列 ...
- 第14章:MongoDB-聚合操作--聚合管道
① 聚合管道是MongoDB2.2版本引入的新功能.它由阶段(Stage)组成,文档在一个阶段处理完毕后,聚合管道会把处理结果传到下一个阶段. 每个阶段用阶段操作符(Stage Operators)定 ...
- ajax 简单实例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script> ...
- 1, 2, and 4 symbols per clock中数据排列
图片来自High-DenitionMultimedia Interface (HDMI) IP Core User Guide 在自己处理的过程中很多细节的东西必须要清楚. 今天想自己从RGB数据中 ...
- Ajax传数据到servlet
//jsp代码 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" ...