与WPF相同Windows 8.1应用中也具有高级触控操作(Manipulation),其中包含了三种常见的触屏手势:平移、缩放、旋转,通过以下四种事件可为控件实现各种触控操作:ManipulationStarting、ManipulationStarted、ManipulationDelta、ManipulationInertiaStarting、ManipulationCompleted。
开发之触控操作-windows应用程序开发">
打开Visual Studio 2013 Preview,新建Windows Store应用。在XAML代码中添加Image控件,将ManipulationMode设置为ALL(也可按需要选择不同模式),并为其添加ManipulationStarting、ManipulationDelta、ManipulationCompleted事件,以便后续实现相关手势操作内容。RenderTransform中的CompositeTransform是一个控件变形组合,可容纳多种变形属性,如平移、旋转、缩放。
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> <Canvas> <Image x:Name="imageElement" Source="images/cliff.jpg" Height="460" Width="758" Canvas.Left="300" Canvas.Top="150" ManipulationMode="All" ManipulationStarting="image_ManipulationStarting" ManipulationDelta="image_ManipulationDelta" ManipulationCompleted="image_ManipulationCompleted"> <Image.RenderTransform> <CompositeTransform x:Name="imageCT" /> </Image.RenderTransform> </Image> </Canvas> </Grid>
查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/
接下来,编写每个事件的具体内容,如下代码:
private void image_ManipulationStarting(object sender, ManipulationStartingRoutedEventArgs e) { e.Handled = true; } private void image_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) { FrameworkElement element = e.OriginalSource as FrameworkElement; element.Opacity = 0.5; imageCT.TranslateX += e.Delta.Translation.X; imageCT.TranslateY += e.Delta.Translation.Y; imageCT.ScaleX *= e.Delta.Scale; imageCT.ScaleY *= e.Delta.Scale; imageCT.Rotation += e.Delta.Rotation; } private void image_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) { FrameworkElement element = e.OriginalSource as FrameworkElement; element.Opacity = 1; }
这些代码很好理解,当ManipulationDelta触发后,首先将控件透明度设置为0.5,然后捕捉触控操作并对TranslateX、TranslateY(平移);ScaleX、ScaleY(缩放)、Rotation(旋转)进行修改。最后ManipulationCompleted结束后将控件透明度恢复即可。按下F5键看看效果如何。
作者:李敬然(Gnie)
出处:{GnieTech} (http://www.cnblogs.com/gnielee/)
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索控件
, c++ 函数平移缩放问题
, element
, 平移
rotation
windows应用程序开发、windows开发ios应用、windows桌面应用开发、windows应用开发、windows10应用开发,以便于您获取更多的相关知识。