标签:des style class blog code color
创建一个基本的 Windows Phone 应用程序并添加 TiltEffect 类文件。
添加要倾斜的控件的分类。
全局应用 IsTiltEnabled 依赖项属性,以便为所有的指定控件提供倾斜功能。
对一个控件应用 SuppressTilt 依赖项属性,以抑制倾斜效果。
从“开始”菜单启动 Visual Studio 2010 Express for Windows Phone。
通过选择“文件 | 新建项目”菜单命令来创建一个新项目。
将显示“新建项目”窗口。展开“Visual C#”模板,然后选择“Silverlight for Windows Phone”模板。
选择“Windows Phone 应用程序”模板。填写所需的项目“名称”。
单击“确定”。将创建一个新项目并在 Visual Studio 设计器窗口中打开 MainPage.xaml。
在“解决方案资源管理器”中,右键单击该项目,单击“添加”,然后单击“新项”。选择“类”并将该文件重命名为 TiltEffect.cs,然后单击位于页面底部的“添加”。
下载 ControlTiltEffect 示例:控件倾斜效果示例。
下载该解决方案之后,必须执行以下步骤。
在下载的解决方案中找到 TiltEffect.cs 文件。
将 TiltEffect.cs 文件导入到您的项目中。
在“解决方案资源管理器”中右键单击该项目,单击“添加”,然后选择“现有项”。浏览 TiltEffect.cs 文件,然后单击“添加”。
将 TiltEffect.cs 文件中的命名空间更改为您项目的命名空间名称。例如,将代码复制到该文件中之后,命名空间将为 ControlTiltEffect:
namespace ControlTiltEffect
将该命名空间更改为您项目的命名空间。
在 MainPage.xaml 中,将以下代码添加到 XAML 代码的接近页面底部的“Content Panel”部分下面。该部分前面的注释为“<!--ContentPanel - 将其他内容置于此处-->。”删除已填充该部分的开始和结束 Grid 标记。
|
1
2
3
4
5
6
7
8
9
10
11
12
13 |
<Grid x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,0"> <Button Width="186"
Height="185"
Content="Button"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="9,20,0,0"
/> <Button Content="Button (Suppressed)"
Height="150"
HorizontalAlignment="Left"
Margin="37,0,0,161"
VerticalAlignment="Bottom"
Width="380"/> <CheckBox Content="CheckBox"
Height="72"
HorizontalAlignment="Left"
Margin="235,25,0,0"
Name="checkBox1"
VerticalAlignment="Top"
/> <RadioButton Content="RadioButton"
Height="72"
HorizontalAlignment="Left"
Margin="235,103,0,0"
Name="radioButton1"
VerticalAlignment="Top"
/> <HyperlinkButton Content="HyperlinkButton"
Height="30"
HorizontalAlignment="Left"
Margin="25,211,0,0"
Name="hyperlinkButton1"
VerticalAlignment="Top"
Width="409"
/> <ListBox Height="110"
HorizontalAlignment="Left"
Margin="6,472,0,0"
Name="listBox1"
VerticalAlignment="Top"
Width="460"
ItemsSource="{Binding}"
> <ListBoxItem Content="First ListBoxItem"
></ListBoxItem> <ListBoxItem Content="Second ListBoxItem"
></ListBoxItem> <ListBoxItem Content="Third ListBoxItem"
></ListBoxItem> <ListBoxItem Content="Fourth ListBoxItem"
></ListBoxItem> </ListBox> </Grid> |

在 MainPage.xaml 中,向页面顶部添加以下命名空间声明:
|
1 |
xmlns:local="clr-namespace:[Namespace]" |
在 MainPage.xaml 中,在页面顶部添加并启用依赖项属性 IsTiltEnabled:
|
1 |
local:TiltEffect.IsTiltEnabled="True" |
在该页面上,在 XAML 代码中找到 Content 属性设置为 Button (Suppressed) 的 Button 控件。将代码修改为以下内容:
|
1 |
<Button Content="Button (Suppressed)"
Height="150"
HorizontalAlignment="Left"
Margin="37,0,0,161"
VerticalAlignment="Bottom"
Width="380"
local:TiltEffect.SuppressTilt="True"/> |
通过选择“调试 | 启动调试”菜单命令运行应用程序。这将打开模拟器窗口并启动该应用程序,或者部署到您选择的设备。运行应用程序之后,您应该看到所有控件都应用了倾斜效果。唯一的例外是启用了抑制倾斜依赖项属性的按钮。
标签:des style class blog code color
原文地址:http://www.cnblogs.com/joetoalways/p/3705971.html