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 ...
随机推荐
- java连接数据库以及连接参数格式
//链接数据库代码部分 下面具有连接的基本参数可以对照修改(参数存放在file下面的database.properties下面) //参数存放在file下面的database.properties下 ...
- 为什么要用jvm .
挚享科技 2018.4.8 运行java程序字节码,实现跨平台.. Java语言使用Java虚拟机屏蔽了与具体平台相关的信息,使得Java语言编译程序只需生成 在Java虚拟机上运行的目标代码(字节码 ...
- 微信JSSDK接口previewImage
<div class="pics"> <img src="http://pic1.ytqmx.com:82/2015/0409/01/15.jpg!96 ...
- CentOS Linux更改MySQL数据库目录位置具体操作
引言: 由于MySQL的数据库太大,默认安装的/var盘已经再也无法容纳新增加的数据,没有办法,只能想办法转移数据的目录. 下面我整理一下把MySQL从/var/lib/mysql目录下面转移到/ho ...
- GCC选项之-M
大多数的C/C++编译器都支持一个“-M”的选项,即自动找寻源文件中包含的头文件.举个例子,比如mian.c包含有如下头文件. #include <stdio.h> #include &q ...
- 3、iOS Xcode创建protocol(代理).h文件
- Svn项目管理工具
1 svn介绍 1.1 项目管理中的版本控制问题 通常软件开发由多人协作开发,如果对代码文件.配置文件.文档等没有进行版本控制,将会出现很多问题: 备份多个版本,占用磁盘空间大 解 ...
- (5)How to let go of being a "good" person — and become a better person
https://www.ted.com/talks/dolly_chugh_how_to_let_go_of_being_a_good_person_and_become_a_better_perso ...
- High-radix routers
The idea is to reduce H (hops), by adding explicit links between physically distant routers, thus re ...
- Apache hadoop安装配置
1.网络中继更改问题 命令: vi /etc/sysconfig/network-scripts/ifcfg-eth0 需要修改的代码 DEVICE=eth0 HWADDR=00:0C:29:11 ...