WP7 开发 基础知识与问题积累
基础知识点:
1、获取WP7的DeviceUniqueId:
public string GetDeviceUniqueId() { string strUniqueId = null;
object uniqueId = DeviceExtendedProperties.GetValue("DeviceUniqueId"); if (uniqueId != null) { byte[] uniqueBytes = (byte[]) uniqueId; strUniqueId = Convert.ToBase64String(uniqueBytes); } return strUniqueId; }
2、添加页面切换动画(需要使用到Microsoft.Phone.Controls.Toolkit):
修改App.xaml.cs文件:
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the frame but don't set it as RootVisual yet; this allows the splash
// screen to remain active until the application is ready to render.
// RootFrame = new PhoneApplicationFrame();
RootFrame = new TransitionFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
// Handle navigation failures
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
// Ensure we don't initialize again
phoneApplicationInitialized = true;
}
MainPage.xaml文件:
<phone:PhoneApplicationPage x:Class="MyProject.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:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" SupportedOrientations="Portrait" Orientation="Portrait" shell:SystemTray.IsVisible="True">
// 设置页面切换动画 <toolkit:TransitionService.NavigationInTransition> <toolkit:NavigationInTransition> <toolkit:NavigationInTransition.Backward> <toolkit:TurnstileTransition Mode="BackwardIn"/> </toolkit:NavigationInTransition.Backward> <toolkit:NavigationInTransition.Forward> <toolkit:TurnstileTransition Mode="ForwardIn"/> </toolkit:NavigationInTransition.Forward> </toolkit:NavigationInTransition> </toolkit:TransitionService.NavigationInTransition> <toolkit:TransitionService.NavigationOutTransition> <toolkit:NavigationOutTransition> <toolkit:NavigationOutTransition.Backward> <toolkit:TurnstileTransition Mode="BackwardOut"/> </toolkit:NavigationOutTransition.Backward> <toolkit:NavigationOutTransition.Forward> <toolkit:TurnstileTransition Mode="ForwardOut"/> </toolkit:NavigationOutTransition.Forward> </toolkit:NavigationOutTransition> </toolkit:TransitionService.NavigationOutTransition> <!--LayoutRoot is the root grid where all page content is placed--> <Grid x:Name="LayoutRoot" Background="Transparent"> </Grid> </phone:PhoneApplicationPage>
个人使用页面切换动画过程中遇到的问题:
1、页面A添加切换动画,页面B未添加切换动画;当A跳转到B时,在切换过程中点击“Back”键,程序会异常退出;
2、页面A与B都添加了切换动画,从A跳转到B,如果在B页面加载前点击“Back”键,会出现页面A、B重叠的现象。
遇到的问题:
1、Canvas中画PolyLine,当PolyLine的开始点与结束点距离过大时,该PolyLine无法显示。
XAML文件:
<Canvas>
<Polyline x:Name="MyPolyLine" Canvas.Left="0" Canvas.Top="400" Stroke="Blue" StrokeThickness="6"/> </Canvas>
CS文件:
private void LoadLine() {
PointCollection pointCollection = new PointCollection();
pointCollection.Add(new Point(0, 0));
pointCollection.Add(new Point(200, 0));
pointCollection.Add(new Point(1000, 0));
pointCollection.Add(new Point(10000, 0));
pointCollection.Add(new Point(20000, 0));
pointCollection.Add(new Point(30000, 0));
// 如果添加此点则PolyLine不显示
// pointCollection.Add(new Point(40000, 0));
this.MyPolyLine.Points = pointCollection; }