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中 ...
随机推荐
- python学习笔记(二)— 集合
s = set()#建立空的集合 s2 = {'}#没有:的为集合,集合天生去重 s3 = {'} #集合是也是无序的 # s2.add('a')#添加值 # s2.remove('2')#删除值 # ...
- 有些有IP的项目,公司不至于测试不行砍项目,但是会砍项目组,把IP收回交给别的团队做(因为一旦一测数据太差,公司(投资人)会判断在二测的时候数据能提升到什么样。说白了就是历史信用问题)
作者:匿名用户链接:https://www.zhihu.com/question/309778033/answer/579761064来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...
- Python慢,为啥还有大公司用?
PyCon 是全世界最大的以 Python 编程语言 为主题的技术大会,大会由 Python 社区组织,每年举办一次.在 Python 2017 上,Instagram 的工程师们带来了一个有关 Py ...
- 使用selenium
1.安装谷歌浏览器 2.安装谷歌浏览器驱动 3.安装selenium包 4.测试 1.安装谷歌浏览器 2.安装谷歌浏览器驱动 打开 http://blog.csdn.net/huilan_ ...
- 如何制作一款HTML5 RPG游戏引擎——第四篇,情景对话
今天我们来实现情景对话.这是一个重要的功能,没有它,游戏将变得索然无味.所以我们不得不来完成它. 但是要知道,使用对话可不是一件简单的事,因为它内部的东西很多,比如说人物头像,人物名称,对话内容... ...
- python全栈开发从入门到放弃之推导式详解
variable = [out_exp_res for out_exp in input_list if out_exp == 2] out_exp_res: 列表生成元素表达式,可以是有返回值的函数 ...
- Outputting Strings in the Console
Outputting Strings in the Console #include <windows.h> class Console {public: enum fore_color ...
- sql server 复制表从一个数据库到另一个数据库
sql server 复制表从一个数据库到另一个数据库 /*不同服务器数据库之间的数据操作*/ --创建链接服务器 exec sp_addlinkedserver 'ITSV ', ' ', 'SQL ...
- Cout<<XXX<<<XXX<<<XXX,是从左到右计算的
int a=1,b=2,c=3; cout<<(c=a+b)<<' '<<(a=b+c)<<' '<<(b=a+c)<<e ...
- Python3 安装第三方包
打开cmd(切记是cmd,不是Python3.6那个敲代码环境)输入 pip3 install numpy 即可(安装numpy包)