与众不同 windows phone (24) - Input(输入)之软键盘类型, XNA 方式启动软键盘, UIElement 的 Touch 相关事件, 触摸涂鸦
原文:与众不同 windows phone (24) - Input(输入)之软键盘类型, XNA 方式启动软键盘, UIElement 的 Touch 相关事件, 触摸涂鸦
作者:webabcd
介绍
与众不同 windows phone 7.5 (sdk 7.1) 之输入
- 指定软键盘的类型
- XNA 方式启动软键盘,并获取用户输入的信息
- UIElement 的 Touch 相关事件
- 涂鸦板
示例
1、演示如何指定软键盘的类型
InputScopeDemo.xaml
<phone:PhoneApplicationPage
x:Class="Demo.Input.Keyboard.InputScopeDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True"> <Grid x:Name="LayoutRoot" Background="Transparent">
<StackPanel Orientation="Vertical"> <!--SIP 包含数字和小数点,按住句号键可以显示“.,-”-->
<TextBox InputScope="Number" /> <!--SIP 按“123”键切换到电话号码键盘,按住句号键可以显示“.,-”-->
<TextBox InputScope="NameOrPhoneNumber" /> <!--SIP 默认显示数字和符号键盘-->
<TextBox InputScope="CurrencyChinese" /> <!--SIP 显示电话拨号键盘-->
<TextBox>
<TextBox.InputScope>
<InputScope>
<InputScopeName NameValue="TelephoneNumber" />
</InputScope>
</TextBox.InputScope>
</TextBox> <!--后台将此 TextBox 的 InputScope 设置为“EmailUserName”-->
<!--SIP 包括 @ 和 .com 键,按住 .com 键可以显示“.org .com .edu .net”-->
<TextBox Name="textBox" KeyDown="textBox_KeyDown" /> </StackPanel>
</Grid> </phone:PhoneApplicationPage>
InputScopeDemo.xaml.cs
/*
* 演示如何指定 SIP(Soft Input Panel)的输入范围
* 本 Demo 只演示常用 SIP 布局,更多的布局请参见:http://msdn.microsoft.com/en-us/library/hh393998(v=vs.92)
*/ using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls; using System.Windows.Navigation; namespace Demo.Input.Keyboard
{
public partial class InputScopeDemo : PhoneApplicationPage
{
public InputScopeDemo()
{
InitializeComponent();
} protected override void OnNavigatedTo(NavigationEventArgs e)
{
/*
* 通过指定 TextBox 的 InputScope 来决定关联 SIP 的布局方式
*
* System.Windows.Input.InputScopeNameValue 枚举有多个值,每个值所对应的 SIP 布局请参见:http://msdn.microsoft.com/en-us/library/hh393998(v=vs.92)
*/ InputScope scope = new InputScope();
InputScopeName name = new InputScopeName(); name.NameValue = InputScopeNameValue.EmailUserName;
scope.Names.Add(name); textBox.InputScope = scope;
} private void textBox_KeyDown(object sender, KeyEventArgs e)
{
// 判断用户是否按下了 SIP 上的回车键
if (e.Key == Key.Enter)
{
MessageBox.Show("用户按下了回车键"); // 转移焦点,虚拟键盘会自动隐藏
this.Focus();
}
}
}
}
2、演示如何以 XNA 方式启动软键盘,并获取用户输入的信息
XNAKeyboard.xaml
<phone:PhoneApplicationPage
x:Class="Demo.Input.Keyboard.XNAKeyboard"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True"> <Grid x:Name="LayoutRoot" Background="Transparent"> <Button Content="显示软键盘" Click="Button_Click" /> </Grid> </phone:PhoneApplicationPage>
XNAKeyboard.xaml.cs
/*
* 演示如何以 XNA 的方式启动软键盘,并获取用户输入的信息
*/ using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls; using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework; namespace Demo.Input.Keyboard
{
public partial class XNAKeyboard : PhoneApplicationPage
{
public XNAKeyboard()
{
InitializeComponent();
} private void LaunchSIP()
{
string title = "请输入文本";
string description = "用于演示 XNA 启动软键盘";
string defaultText = "hello webabcd"; /*
* Guide.BeginShowKeyboardInput(PlayerIndex player, string title, string description, string defaultText, AsyncCallback callback, Object state) - 显示软键盘
* player - 在 windows phone 下只能是 PlayerIndex.One
* title - SIP 对话框上显示的标题
* description - SIP 对话框上显示的描述
* defaultText - SIP 对话框中的文本框的默认文本
* callback - 回调方法
* state - 上下文
*/ Guide.BeginShowKeyboardInput(PlayerIndex.One, title, description, defaultText, GetText, null);
} private void GetText(IAsyncResult result)
{
/*
* 获取用户输入的文本信息
*/
string resultString = Guide.EndShowKeyboardInput(result); this.Dispatcher.BeginInvoke(delegate
{
// 显示用户输入的信息
MessageBox.Show("用户输入的文本:" + resultString);
});
} private void Button_Click(object sender, RoutedEventArgs e)
{
LaunchSIP();
}
}
}
3、演示如何响应 UIElement 的 Touch 相关事件
UIElementTouchEvent.xaml
<phone:PhoneApplicationPage
x:Class="Demo.Input.Touch.UIElementTouchEvent"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True"> <Grid x:Name="LayoutRoot" Background="Transparent">
<StackPanel Orientation="Vertical"> <Rectangle Width="100" Height="100" Fill="Red"
Tap="Rectangle_Tap"
DoubleTap="Rectangle_DoubleTap"
Hold="Rectangle_Hold" /> <TextBlock Name="lblMsg" TextWrapping="Wrap" Margin="0 15 0 0" Text="触摸红色方块以演示 Tap 事件,DoubleTap 事件,Hold 事件" /> </StackPanel>
</Grid> </phone:PhoneApplicationPage>
UIElementTouchEvent.xaml.cs
/*
* 演示 UIElement 支持的 Touch 相关的事件
*
* UIElement - UI 元素
* Tap - 单击事件(事件参数:GestureEventArgs)
* DoubleTap - 双击事件(事件参数:GestureEventArgs)
* Hold - 较长时间触摸某一 UIElement 时所触发的事件(事件参数:GestureEventArgs)
*
* GestureEventArgs
* GetPosition(UIElement relativeTo) - 获取触摸点相对于指定 UIElement 的坐标
*/ using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls; namespace Demo.Input.Touch
{
public partial class UIElementTouchEvent : PhoneApplicationPage
{
public UIElementTouchEvent()
{
InitializeComponent();
} private void Rectangle_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
lblMsg.Text = "Rectangle 的 Tap 事件被触发,触摸点相对于 LayoutRoot 的坐标为:" + e.GetPosition(LayoutRoot).ToString();
} private void Rectangle_DoubleTap(object sender, System.Windows.Input.GestureEventArgs e)
{
lblMsg.Text = "Rectangle 的 DoubleTap 事件被触发,触摸点相对于 LayoutRoot 的坐标为:" + e.GetPosition(LayoutRoot).ToString();
} private void Rectangle_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
lblMsg.Text = "Rectangle 的 Hold 事件被触发,触摸点相对于 LayoutRoot 的坐标为:" + e.GetPosition(LayoutRoot).ToString();
}
}
}
4、演示如何开发涂鸦板程序
InkPresenterDemo.xaml
<phone:PhoneApplicationPage
x:Class="Demo.Input.Touch.InkPresenterDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True"> <Grid x:Name="LayoutRoot" Background="Transparent"> <InkPresenter x:Name="inkPresenter" Cursor="Stylus" Background="Blue"
MouseMove="inkPresenter_MouseMove" MouseLeftButtonDown="inkPresenter_MouseLeftButtonDown"> <TextBlock Text="请涂鸦" /> </InkPresenter> </Grid> </phone:PhoneApplicationPage>
InkPresenterDemo.xaml.cs
/*
* 演示如何把手机当做一个涂鸦板
*
* 本 Demo 只是做一个简单的示例,详细说明在之前的 Silverlight 系列文章中已经写过,请参考 http://www.cnblogs.com/webabcd/archive/2008/11/17/1334768.html
*/ using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls; using System.Windows.Ink; namespace Demo.Input.Touch
{
public partial class InkPresenterDemo : PhoneApplicationPage
{
// 涂鸦笔画对象
private Stroke _newStroke; public InkPresenterDemo()
{
InitializeComponent();
} private void inkPresenter_MouseMove(object sender, MouseEventArgs e)
{
_newStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(inkPresenter));
} private void inkPresenter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
AddStroke();
} private void AddStroke()
{
_newStroke = new Stroke();
_newStroke.DrawingAttributes.Width = 3d;
_newStroke.DrawingAttributes.Height = 3d;
_newStroke.DrawingAttributes.Color = Colors.Green;
_newStroke.DrawingAttributes.OutlineColor = Colors.Red; inkPresenter.Strokes.Add(_newStroke);
}
}
}
OK
[源码下载]
与众不同 windows phone (24) - Input(输入)之软键盘类型, XNA 方式启动软键盘, UIElement 的 Touch 相关事件, 触摸涂鸦的更多相关文章
- 与众不同 windows phone (25) - Input(输入)之捕获 UIElement 之外的触控操作, Silverlight 方式捕获手势操作, XNA 方式捕获手势操作, 多点触控
原文:与众不同 windows phone (25) - Input(输入)之捕获 UIElement 之外的触控操作, Silverlight 方式捕获手势操作, XNA 方式捕获手势操作, 多点触 ...
- 背水一战 Windows 10 (68) - 控件(控件基类): UIElement - Pointer 相关事件, Tap 相关事件, Key 相关事件, Focus 相关事件
[源码下载] 背水一战 Windows 10 (68) - 控件(控件基类): UIElement - Pointer 相关事件, Tap 相关事件, Key 相关事件, Focus 相关事件 作者: ...
- 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom
[源码下载] 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom 作者:webab ...
- 与众不同 windows phone (48) - 8.0 其它: C# 调用 C++
[源码下载] 与众不同 windows phone (48) - 8.0 其它: C# 调用 C++ 作者:webabcd 介绍与众不同 windows phone 8.0 之 其它 C# 中调用 W ...
- 与众不同 windows phone (21) - Device(设备)之摄像头(拍摄照片, 录制视频)
原文:与众不同 windows phone (21) - Device(设备)之摄像头(拍摄照片, 录制视频) [索引页][源码下载] 与众不同 windows phone (21) - Device ...
- INPUT输入子系统【转】
转自:https://www.cnblogs.com/deng-tao/p/6094049.html 1.Linux系统支持的输入设备繁多,例如键盘.鼠标.触摸屏.手柄或者是一些输入设备像体感输入等等 ...
- 背水一战 Windows 10 (24) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令
[源码下载] 背水一战 Windows 10 (24) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令 作者:webabcd ...
- input输入子系统
一.什么是input输入子系统? 1.Linux系统支持的输入设备繁多,例如键盘.鼠标.触摸屏.手柄或者是一些输入设备像体感输入等等,Linux系统是如何管理如此之多的不同类型.不同原理.不同的输入信 ...
- 与众不同 windows phone (37) - 8.0 文件系统: StorageFolder, StorageFile, 通过 Uri 引用文件, 获取 SD 卡中的文件
[源码下载] 与众不同 windows phone (37) - 8.0 文件系统: StorageFolder, StorageFile, 通过 Uri 引用文件, 获取 SD 卡中的文件 作者:w ...
随机推荐
- MSDN 杂志:UI 前沿技术 - WPF 中的多点触控操作事件
原文 MSDN 杂志:UI 前沿技术 - WPF 中的多点触控操作事件 UI 前沿技术 WPF 中的多点触控操作事件 Charles Petzold 下载代码示例 就在过去几年,多点触控还只是科幻电 ...
- Java:利用java Timer类实现定时执行任务的功能
一.概述 在java中实现定时执行任务的功能,主要用到两个类,Timer和TimerTask类.其中Timer是用来在一个后台线程按指定的计划来执行指定的任务.TimerTask一个抽象类,它的子类代 ...
- http异步请求
1.加载异步请求包文件 2.java代码 package com.example.asynchttp; import org.apache.http.Header; import com.loopj. ...
- PHP - 点击更换头像
原理: 操作流程: 首先点击头像图片,弹出选择窗口,选中其中一个则窗口推出头像更换. 效果: 主页面代码: <tr> <td>头像:</td> <td> ...
- Android Content Provider的启动过程源码分析
本文參考Android应用程序组件Content Provider的启动过程源码分析http://blog.csdn.net/luoshengyang/article/details/6963418和 ...
- 对于一颗完全二叉树,要求给所有节点加上一个pNext指针,指向同一层的相邻节点-----层序遍历的应用题
题目:对于一颗完全二叉树,要求给所有节点加上一个pNext指针,指向同一层的相邻节点:如果当前节点已经是该层的最后一个节点,则将pNext指针指向NULL:给出程序实现,并分析时间复杂度和空间复杂度. ...
- Qt遍历图片文件
原地址:http://blog.sina.com.cn/s/blog_5c70dfc80100tgff.html //实现遍历某个文件下的图片文件 //如果想遍历其余类型文件,方法也一样,只需简单修改 ...
- high volume logging
logging 是现在系统中必不可少的组件了.市面上已经有很多很多非常成熟的日志产品,log*系列就是一个典型代表.对于erlang系统来说,也有很多,比如error_logger, disk_log ...
- Linux 静态库&动态库调用
1.什么是库在windows平台和linux平台下都大量存在着库.本质上来说库是一种可执行代码的二进制形式,可以被操作系统载入内存执行.由于windows和linux的本质不同,因此二者库的二进制是不 ...
- linux安装Eclipse c++环境
yum install eclipse yum install eclipse-cdt