與WPF相同Windows 8.1應用中也具有高級觸控操作(Manipulation),其中包含了三種常見的觸屏手勢:平移、縮放、旋轉,通過以下四種事件可為控件實現各種觸控操作:ManipulationStarting、ManipulationStarted、ManipulationDelta、ManipulationInertiaStarting、ManipulationCompleted。

打開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>
查看本欄目