花了一天时间小键盘基本功能已完成,先看看效果图吧!

默认:

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">&lt;-</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>

存在的问题:还不能自动定位,弹出键盘需要手动控制,这些以后会解决的

周末愉快!

本文地址:http://www.cnblogs.com/liuxiaobo93/p/3915468.html 暮雨冰蓝

C#(Wpf)实现小键盘的更多相关文章

  1. WPF 触摸屏小键盘样式

    WPF程序,用于平板时,一些输入数量的地方我们需要弹出小键盘输入,这个键盘可以调系统的,也可以自己写. 分享个我现在用的一个数字键盘界面. <Window xmlns:dxe="htt ...

  2. WinForm数字小键盘/WPF数字小键盘

    模仿原本的WinForm触摸屏小键盘制作WPF触摸屏小键盘 原WinForm触摸屏小键盘样式(WinForm采用Krypton系列控件)如下图: Designer代码如下: // // BtnNum1 ...

  3. 在WPF中使用依赖注入的方式创建视图

    在WPF中使用依赖注入的方式创建视图 0x00 问题的产生 互联网时代桌面开发真是越来越少了,很多应用都转到了浏览器端和移动智能终端,相应的软件开发上的新技术应用到桌面开发的文章也很少.我之前主要做W ...

  4. MVVM框架从WPF移植到UWP遇到的问题和解决方法

    MVVM框架从WPF移植到UWP遇到的问题和解决方法 0x00 起因 这几天开始学习UWP了,之前有WPF经验,所以总体感觉还可以,看了一些基础概念和主题,写了几个测试程序,突然想起来了前一段时间在W ...

  5. MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息

    MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二 ...

  6. MVVM模式解析和在WPF中的实现(五)View和ViewModel的通信

    MVVM模式解析和在WPF中的实现(五) View和ViewModel的通信 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 M ...

  7. MVVM设计模式和WPF中的实现(四)事件绑定

    MVVM设计模式和在WPF中的实现(四) 事件绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  8. MVVM模式解析和在WPF中的实现(三)命令绑定

    MVVM模式解析和在WPF中的实现(三) 命令绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  9. MVVM模式和在WPF中的实现(二)数据绑定

    MVVM模式解析和在WPF中的实现(二) 数据绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

随机推荐

  1. jquery的强大选择器

    $("#myELement")    选择id值等于myElement的元素,id值不能重复在文档中只能有一个id值是myElement所以得到的是唯一的元素 $("di ...

  2. 【转】通过ionice和nice降低shell脚本运行的优先级

    对于一些运行时会造成系统满载的脚本, 例如数据库备份, 会影响当时其他服务的响应速度, 可以通过ionice和nice对其IO优先级和CPU优先级进行调整例如降低"/usr/local/bi ...

  3. LeetCode_Insertion Sort List

    题目:Sort a linked list using insertion sort,即仿照插入排序(直接插入排序)对一个链表排序. 插入排序的思想:总共进行n-1趟排序,在排列第i个元素时,前面的i ...

  4. D. Two Paths---cf14D(树的直径)

    题目链接:http://codeforces.com/problemset/problem/14/D 题意:有n个city ; n-1条路:求断开一条路之后分成的两部分所构成的树的直径的积最大是多少: ...

  5. 最长回文---hdu3068 (回文串 manacher 算法模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3068 题意很清楚:就是求一个串s的子串中最长回文串的长度:这类题用到了manacher算法 #incl ...

  6. (0.2.6)Mysql安装——编译安装

    (0.2.6)Mysql安装——编译安装 待完善

  7. 每人涨10%的工资,涨的前一共不超过5万,从低工资往高工资的人涨,超过5W则停止涨,问涨的钱花了多少,多少人获得了涨薪。

    ;with test(CID,money,NewAmount) as ( SELECT Row_Number() over ( order by money ) as CID ,money ,mone ...

  8. 002-shell变量定义、使用、字符串、数组、注释

    一.变量定义 定义变量时,变量名不加美元符号($) name="lhx" 注意,变量名和等号之间不能有空格.同时,变量名的命名须遵循如下规则: 命名只能使用英文字母,数字和下划线, ...

  9. PHP魔术方法和魔术常量介绍及使用

    魔术方法(Magic methods) PHP中把以两个下划线__开头的方法称为魔术方法,这些方法在PHP中充当了举足轻重的作用. 魔术方法包括: __construct(),类的构造函数 __des ...

  10. 20165324《Java程序设计》第七周

    20165324<Java程序设计>第七周 教材学习内容总结 第11章 JDBC与MySOLz数据库 MySQL数据库管理系统,简称MySQL. 使用步骤: 启动MySQL数据库服务 器建 ...