与众不同 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 ...
随机推荐
- Android开发--CardView使用
Android5.0中向我们介绍了一个全新的控件–CardView,从本质上看,可以将CardView看做是FrameLayout在自身之上添加了圆角和阴影效果.请注意:CardView被包装为一种布 ...
- Makefile学习(二)[第二版]
复杂实例 #演示样例1:在上一个演示样例的基础上再添加一个可运行文件03test[改动之处已标红] .PHONY: clean all CC = gcc CFLAGS = -Wall -g BIN = ...
- mp3播放器
1.视图 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:too ...
- c语言,数据类型转换
在执行算术运算时,计算机比C语言的限制更多.为了让计算机执行算术运算,通常要求操作数有相同的大小(即位的数量相同),并且要求存储的方式也相同.计算机可能可以直接将两个16位整数相加,但是不能直接将16 ...
- iOS 编程之 使用 Xcode6配置.pch文件
刚上手 Xcode6 的人,总会发现之前在 6 之前常常会在“利用名-Prefix.pch”这个文件中来配置我们全局要用到的头文件,但是 xcode6 没有了,人家说,这类东西有时候也会出现1些稀里糊 ...
- ORA-01403: no data found
在项目的存储过程中有这样一句话 select jgdm,jgmc into parm_mrjgdm,parm_mrjgmc From BL_KHXX where jgdm=PARM_JGDM; 每次 ...
- 流行python服务器框架
流行python服务器框架 1.tonardo---- 多并发.轻量级应用, “非阻塞”的web 容器.类似tomcat.这个大家太熟悉了,就不多说了. 2.Twisted---- Twisted ...
- VC 对话框背景颜色、控件颜色
系统环境:Windows 7软件环境:Visual C++ 2008 SP1本次目的:为对话框设置背景颜色.控件颜色 既然MFC对话框不好开发,那么现在我们来开始美化我们的对话框.为对话框设置背景颜色 ...
- 对于一颗完全二叉树,要求给所有节点加上一个pNext指针,指向同一层的相邻节点-----层序遍历的应用题
题目:对于一颗完全二叉树,要求给所有节点加上一个pNext指针,指向同一层的相邻节点:如果当前节点已经是该层的最后一个节点,则将pNext指针指向NULL:给出程序实现,并分析时间复杂度和空间复杂度. ...
- Twenty Newsgroups Classification任务之二seq2sparse
seq2sparse对应于mahout中的org.apache.mahout.vectorizer.SparseVectorsFromSequenceFiles,从昨天跑的算法中的任务监控界面可以看到 ...