CodePlex是很多托管Windows Phone 7项目的普通的地方之一,它对于许多开发者来说可以算是权威的,因为它是免费的、能够托管源码、二进制文件、文档、工作项目、讨论,还支持直接插入到Visual Studio中。这就是说,它适用于有不同需求、喜好的开发者。
还有一个新的Windows Phone 7项目托管的地方,可能微软领域的开发者没有考虑到或曾听过,但是不久之后就会意识到。
谁在负责这个神秘项目?诺基亚!是的,诺基亚。下面来看一个典型的托管项目。
Bubble Level Silverlight
举个简单的Silverlight例子,使用加速度传感器来计算设备的倾斜度,并以泡泡的位置来显示水平度。
特别值得注意的是wiki页面,在这里你可以看到一个伟大的故事,包括介绍这个项目是如何创建并完成的。
这是一个简单的应用程序,但有时简单正是你所需要的。下面是项目的截图和代码片段。
C#代码
- /// <summary>
- /// Updates the position of the bubble in the glass tube.
- /// </summary>
- /// <param name="e">Contains the accelerometer reading value.</param>
- protected void UpdateBubble(AccelerometerReadingEventArgs e)
- {
- const double RADIANS_TO_DEGREE = 57.2957795;
- double divider = Math.Sqrt(e.X * e.X + e.Y * e.Y + e.Z * e.Z);
- // Calculating the angle + using low pass factor 20 %.
- // Values from all three accelerometers are used to get more precise reading on y-axis.
- m_Angle += (Math.Acos(e.Y / divider) * RADIANS_TO_DEGREE - 90 - m_Angle) * 0.2;
- double angle;
- // Depending on the orientation, invert the accelerometer value
- if (Orientation == PageOrientation.LandscapeLeft)
- {
- angle = -m_Angle + m_CalibrationFactor;
- }
- else
- {
- angle = m_Angle - m_CalibrationFactor;
- }
- const double MAX_ANGLE = 20.0;
- // Restrict the angle value to the range -20 and 20 degrees.
- if (angle > MAX_ANGLE)
- {
- angle = MAX_ANGLE;
- }
- else if (angle < -MAX_ANGLE)
- {
- angle = -MAX_ANGLE;
- }
- // Set the bubble position.
- BubbleTransform.X = angle / MAX_ANGLE * (Reflection.Width / 2 - Bubble.Width / 2);
- }
/// <summary>
/// Updates the position of the bubble in the glass tube.
/// </summary>
/// <param name="e">Contains the accelerometer reading value.</param>
protected void UpdateBubble(AccelerometerReadingEventArgs e)
{
const double RADIANS_TO_DEGREE = 57.2957795;
double divider = Math.Sqrt(e.X * e.X + e.Y * e.Y + e.Z * e.Z);
// Calculating the angle + using low pass factor 20 %.
// Values from all three accelerometers are used to get more precise reading on y-axis.
m_Angle += (Math.Acos(e.Y / divider) * RADIANS_TO_DEGREE - 90 - m_Angle) * 0.2;
double angle;
// Depending on the orientation, invert the accelerometer value
if (Orientation == PageOrientation.LandscapeLeft)
{
angle = -m_Angle + m_CalibrationFactor;
}
else
{
angle = m_Angle - m_CalibrationFactor;
}
const double MAX_ANGLE = 20.0;
// Restrict the angle value to the range -20 and 20 degrees.
if (angle > MAX_ANGLE)
{
angle = MAX_ANGLE;
}
else if (angle < -MAX_ANGLE)
{
angle = -MAX_ANGLE;
}
// Set the bubble position.
BubbleTransform.X = angle / MAX_ANGLE * (Reflection.Width / 2 - Bubble.Width / 2);
}
VIA http://channel9.msdn.com/coding4fun/blog/Theres-a-new-Windows-Phone-7-project-place-in-town