C#(Wpf)实现小键盘
花了一天时间小键盘基本功能已完成,先看看效果图吧!

默认:
Shift:
Caps Lock:
Button style
<Style x:Key="KeyButton" TargetType="Button">
<Setter Property="Background" Value="White"/>
<Setter Property="Margin" Value="1,2"/>
<Setter Property="Width" Value="24"/>
<Setter Property="Height" Value="24"/>
<Setter Property="BorderThickness" Value=".5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimation Duration="0" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" To="#47C9FB"/>
<ColorAnimation Duration="0" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" To="#2BA8E8"/>
<ColorAnimation Duration="0" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)" To="#1097D7"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ColorAnimation Duration="0" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" To="#1097D7"/>
<ColorAnimation Duration="0" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" To="#2BA8E8"/>
<ColorAnimation Duration="0" Storyboard.TargetName="BackgroundGradient" Storyboard.TargetProperty="(Rectangle.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)" To="#47C9FB"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled" />
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused" />
<VisualState x:Name="Unfocused" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="Background" Background="White" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
<Grid Background="{TemplateBinding Background}">
<Rectangle x:Name="BackgroundGradient" >
<Rectangle.Fill>
<LinearGradientBrush StartPoint=".5,0" EndPoint=".5,1">
<GradientStop Color="White" Offset="0" />
<GradientStop Color="White" Offset="0.4" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</Border>
<ContentPresenter
x:Name="contentPresenter"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Window style
<Style TargetType="{x:Type local:KeyBoard}">
<Setter Property="Width" Value="360px"></Setter>
<Setter Property="Height" Value="108px"></Setter>
<Setter Property="AllowsTransparency" Value="true"/>
<Setter Property="ResizeMode" Value="NoResize"/>
<Setter Property="WindowStyle" Value="None"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:KeyBoard}">
<Border Background="#2092D8"
BorderBrush="#043150"
BorderThickness="1" CornerRadius="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<Button x:Name="btnNum2" Margin="10,2,1,2" Style="{StaticResource KeyButton}">2</Button>
<Button x:Name="btnNum3" Style="{StaticResource KeyButton}">3</Button>
<Button x:Name="btnNum4" Style="{StaticResource KeyButton}">4</Button>
<Button x:Name="btnNum5" Style="{StaticResource KeyButton}">5</Button>
<Button x:Name="btnNum6" Style="{StaticResource KeyButton}">6</Button>
<Button x:Name="btnNum7" Style="{StaticResource KeyButton}">7</Button>
<Button x:Name="btnNum8" Style="{StaticResource KeyButton}">8</Button>
<Button x:Name="btnNum9" Style="{StaticResource KeyButton}">9</Button>
<Button x:Name="btnNum0" Style="{StaticResource KeyButton}">0</Button>
<Button x:Name="btnDot" Style="{StaticResource KeyButton}">`</Button>
<Button x:Name="btnNum1" Style="{StaticResource KeyButton}">1</Button>
<Button x:Name="btnDelete" Style="{StaticResource KeyButton}" Width="45"><-</Button>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<Button x:Name="btnShift" Margin="2,2,1,2" Style="{StaticResource KeyButton}" Width="30">Shift</Button>
<Button x:Name="btnBackslant" Style="{StaticResource KeyButton}">\</Button>
<Button x:Name="btnLParenthesis" Style="{StaticResource KeyButton}">[</Button>
<Button x:Name="btnRParenthesis" Style="{StaticResource KeyButton}">]</Button>
<Button x:Name="btnSemicolon" Style="{StaticResource KeyButton}">;</Button>
<Button x:Name="btnSQuotes" Style="{StaticResource KeyButton}">'</Button>
<Button x:Name="btnComma" Style="{StaticResource KeyButton}">,</Button>
<Button x:Name="btnPeriod" Style="{StaticResource KeyButton}">.</Button>
<Button x:Name="btnSlant" Style="{StaticResource KeyButton}">/</Button>
<Button x:Name="btnSub" Style="{StaticResource KeyButton}">-</Button>
<Button x:Name="btnEquip" Style="{StaticResource KeyButton}">=</Button>
<Button x:Name="btnCapsLock" Style="{StaticResource KeyButton}" Width="62">Caps Lock</Button>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="2">
<Button x:Name="btnj" Margin="10,2,1,2" Style="{StaticResource KeyButton}">j</Button>
<Button x:Name="btnk" Style="{StaticResource KeyButton}">k</Button>
<Button x:Name="btnl" Style="{StaticResource KeyButton}">l</Button>
<Button x:Name="btnm" Style="{StaticResource KeyButton}">m</Button>
<Button x:Name="btna" Style="{StaticResource KeyButton}">a</Button>
<Button x:Name="btnb" Style="{StaticResource KeyButton}">b</Button>
<Button x:Name="btnc" Style="{StaticResource KeyButton}">c</Button>
<Button x:Name="btnd" Style="{StaticResource KeyButton}">d</Button>
<Button x:Name="btne" Style="{StaticResource KeyButton}">e</Button>
<Button x:Name="btnf" Style="{StaticResource KeyButton}">f</Button>
<Button x:Name="btng" Style="{StaticResource KeyButton}">g</Button>
<Button x:Name="btnh" Style="{StaticResource KeyButton}">h</Button>
<Button x:Name="btni" Style="{StaticResource KeyButton}">i</Button>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="3">
<Button x:Name="btnp" Margin="10,2,1,2" Style="{StaticResource KeyButton}">p</Button>
<Button x:Name="btnq" Style="{StaticResource KeyButton}">q</Button>
<Button x:Name="btnr" Style="{StaticResource KeyButton}">r</Button>
<Button x:Name="btns" Style="{StaticResource KeyButton}">s</Button>
<Button x:Name="btnt" Style="{StaticResource KeyButton}">t</Button>
<Button x:Name="btnu" Style="{StaticResource KeyButton}">u</Button>
<Button x:Name="btnv" Style="{StaticResource KeyButton}">v</Button>
<Button x:Name="btnw" Style="{StaticResource KeyButton}">w</Button>
<Button x:Name="btnx" Style="{StaticResource KeyButton}">x</Button>
<Button x:Name="btny" Style="{StaticResource KeyButton}">y</Button>
<Button x:Name="btnz" Style="{StaticResource KeyButton}">z</Button>
<Button x:Name="btnn" Style="{StaticResource KeyButton}">n</Button>
<Button x:Name="btno" Style="{StaticResource KeyButton}">o</Button>
</StackPanel>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
存在的问题:还不能自动定位,弹出键盘需要手动控制,这些以后会解决的
周末愉快!
C#(Wpf)实现小键盘的更多相关文章
- WPF 触摸屏小键盘样式
WPF程序,用于平板时,一些输入数量的地方我们需要弹出小键盘输入,这个键盘可以调系统的,也可以自己写. 分享个我现在用的一个数字键盘界面. <Window xmlns:dxe="htt ...
- WinForm数字小键盘/WPF数字小键盘
模仿原本的WinForm触摸屏小键盘制作WPF触摸屏小键盘 原WinForm触摸屏小键盘样式(WinForm采用Krypton系列控件)如下图: Designer代码如下: // // BtnNum1 ...
- 在WPF中使用依赖注入的方式创建视图
在WPF中使用依赖注入的方式创建视图 0x00 问题的产生 互联网时代桌面开发真是越来越少了,很多应用都转到了浏览器端和移动智能终端,相应的软件开发上的新技术应用到桌面开发的文章也很少.我之前主要做W ...
- MVVM框架从WPF移植到UWP遇到的问题和解决方法
MVVM框架从WPF移植到UWP遇到的问题和解决方法 0x00 起因 这几天开始学习UWP了,之前有WPF经验,所以总体感觉还可以,看了一些基础概念和主题,写了几个测试程序,突然想起来了前一段时间在W ...
- MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息
MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二 ...
- MVVM模式解析和在WPF中的实现(五)View和ViewModel的通信
MVVM模式解析和在WPF中的实现(五) View和ViewModel的通信 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 M ...
- MVVM设计模式和WPF中的实现(四)事件绑定
MVVM设计模式和在WPF中的实现(四) 事件绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
- MVVM模式解析和在WPF中的实现(三)命令绑定
MVVM模式解析和在WPF中的实现(三) 命令绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
- MVVM模式和在WPF中的实现(二)数据绑定
MVVM模式解析和在WPF中的实现(二) 数据绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
随机推荐
- icomoon.io生成字体图标
1. 准备svg图片 2. 打开icomoon选择icomoon App 3. import icons 上传本地的svg图片 4. 点击选中以后点击generate fonts形成字体图标 5. p ...
- LINUX内核分析20133201
实验:通过汇编一个简单的C程序,分析汇编代码理解计算机是如何工作的 学号:20133201 姓名:李冬辉 注: 原创作品转载请注明出处 +<Linux内核分析>MOOC课程http://m ...
- 转:C语言的编译链接过程的介绍
11:42:30 C语言的编译链接过程要把我们编写的一个c程序(源代码)转换成可以在硬件上运行的程序(可执行代码),需要进行编译和链接.编译就是把文本形式源代码翻译为机器语言形式的目标文件的过程.链接 ...
- virtIO前后端notify机制详解
2016-11-15 本来这是在前端驱动后期分析的,但是这部分内容比较多,且分析了后端notify前端的机制,所以还是单独拿出一节分析比较好! 还是拿网络驱动部分做案例,网络驱动部分有两个队列,(忽略 ...
- 7.Git工作区和暂存区
Git和其他版本控制系统如SVN的一个不同之处就是有暂存区的概念. 先来看名词解释. 1.工作区(Working Directory) 就是你在电脑里能看到的目录,比如我的test文件夹就是一个工作区 ...
- tornado调用ioloop TracebackFuture实现非堵塞的模块
转载http://xiaorui.cc/2014/11/26/tornado调用ioloop-tracebackfuture实现非堵塞的模块/ 当然实现的方法,还是存在点问题的, 但是最少流程是跑通了 ...
- redis的客户端medis
medis是用js写的redis客户端工具,界面很好用,也很有用.点击这里可以下载到mac下的软件包. 下面是截图: 完结.
- Mac Angular打包报错xcode-select: error: tool 'xcodebuild' requires Xcode
Mac Angular打包报错: Error: xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer ...
- 工作笔记——限定input上传文件对话框中能选取的文件的格式
原文:http://www.dengzhr.com/frontend/1059 input[file]标签的accept属性可用于指定上传文件的 MIME类型 . 例如,想要实现默认上传图片文件的代码 ...
- 前端须知的http header
文件信息: Content-Type: application/x-javascript Content-Length: 2000 Content-Type:指定请求和响应的内容类型,如果未指定即为t ...