|
Silverlight支持了两种不同应用程序接口用于多点触控,所以很容易区分低级和高级,低级应用都是基于Touch.FrameReported事件,非常类似于XNA的TouchPanel,但是它是事件,而且不包含手势。
:简单应用:
简单的应用是是基于Touch.FrameReported事件,通过处理 FrameReported 事件并访问 TouchFrameEventArgs 事件数据中的 TouchPoint 详细信息,从而响应触控。FrameReported 事件是在应用程序级别处理的单一事件,而不是公开为可能通过 UI 的对象树路由的特定于元素的事件。因此,不能使用事件处理程序的 sender 参数来确定涉及哪些元素。
:
而高级接口包含了由UIElement类定义的三个事件:ManipulationStarted,,ManipulationDelta,ManipulationCompleted.。
ManipulationStarted事件对应自己的参数ManipulationStartedEventArgs
xaml
Code:
public partial class MainPage : PhoneApplicationPage
{
Random rand = new Random();
public MainPage()
{
InitializeComponent();
}
void OnTextBlockManipulationStarted(object sender,
ManipulationStartedEventArgs args)
{
TextBlock txtblk = sender as TextBlock;
Color clr = Color.FromArgb(255, (byte)rand.Next(256),
(byte)rand.Next(256),
(byte)rand.Next(256));
txtblk.Foreground = new SolidColorBrush(clr);
args.Complete();
}
}
2:ManipulationDelta:
public partial class MainPage : PhoneApplicationPage
{
Random rand = new Random();
Brush originalBrush;
public MainPage()
{
InitializeComponent();
originalBrush = txtblk.Foreground;
}
protected override void OnManipulationStarted(ManipulationStartedEventArgs args)
{
if (args.OriginalSource == txtblk)
{
txtblk.Foreground = new SolidColorBrush(
Color.FromArgb(255, (byte)rand.Next(256),
(byte)rand.Next(256),
(byte)rand.Next(256)));
}
else
{
txtblk.Foreground = originalBrush;
}
args.Complete();
base.OnManipulationStarted(args);
}
}
3.ManipulationCompleted
public partial class MainPage : PhoneApplicationPage
{
Random rand = new Random();
Brush originalBrush;
public MainPage()
{
InitializeComponent();
originalBrush = txtblk.Foreground;
}
void OnTextBlockManipulationStarted(object sender,
ManipulationStartedEventArgs args)
{
txtblk.Foreground = new SolidColorBrush(
Color.FromArgb(255, (byte)rand.Next(256),
(byte)rand.Next(256),
(byte)rand.Next(256)));
args.Complete();
args.Handled = true;
}
protected override void OnManipulationStarted(ManipulationStartedEventArgs args)
{
txtblk.Foreground = originalBrush;
args.Complete();
base.OnManipulationStarted(args);
}
} |
|