Windows Phone7程序控件使用Tilt(倾斜)效果

来源:互联网 发布:php采集源码 编辑:程序博客网 时间:2024/05/17 06:27

Windows Phone7 模拟器自带的settings等应用的列表等控件, 点击时有Tilt倾斜的效果, 我们自己写的Demo默认控件是没有这种效果,显得风格与系统不一致,查了一msdn,发现这种效果叫Tilt,并且官方有一个demo:

倾斜特效(Tilt Effect)示例

Windows Phone 控件的倾斜特效(Tilt Effect)为您在普通的控件交互中提供了更加丰富的可视化反馈。当控件被触摸时,它提供了一个“倾斜”状的反馈。控件倾斜特效示例展示了如何在一个应用程序当中实现这种倾斜特效。有关更多如何在应用程序中增加倾斜特效的更多信息,请查看Control Tilt Effect for Windows Phone

下载示例


如何在自己的项目增加Tilt效果呢,可以看看这个

How to: Use the Control Tilt Effect for Windows Phone


其实就是以下几步:

1、在项目中增加  TiltEffect class ,可以从demo中直接复制文件

2、在xaml文件MainPage.xaml开头增加 红色的2句

<phone:PhoneApplicationPage 
    x:Class="HelloWorld.MainPage"
    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"
    xmlns:local="clr-namespace:ControlTiltEffect"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True"
    local:TiltEffect.IsTiltEnabled="True"

3、如果某个控件不想要Tilt效果,则设置 local:TiltEffect.SuppressTilt="True"

例如

<Button Content="Button (Suppressed)" Height="150" HorizontalAlignment="Left" Margin="37,0,0,161" VerticalAlignment="Bottom" Width="380" local:TiltEffect.SuppressTilt="True"/>


挺简单吧,如果还是不清楚自己好好看官方的英文文档吧

原创粉丝点击