在一个解决方案中维护 WP7 和 WP8 版本



基本上,我有一个解决方案,其中包含两个针对Windows Phone 7和Windows Phone 8的项目。我已经将我的WP7项目的页面和类链接到WP8项目(添加为链接),每个项目都包含两个单独的页面TestPage.xamlTestPageWP8.xaml

在WP8

项目中,我添加了额外的WP8 Conditional compilation symbols。所以在我的主页上,我有这样的东西:

        private void onButtonClick(object sender, RoutedEventArgs e)
        {
#if WP8
            NavigationService.Navigate(new Uri("/TestPageWP8.xaml", UriKind.Relative));
#else
            NavigationService.Navigate(new Uri("/TestPage.xaml", UriKind.Relative));
#endif   
        }

问题是我无法打开TestPageWP8,应用程序总是打开TestPage

我的启动项目是WP7,我有诺基亚Lumia 920和610。我错过了一些东西,但是什么?

谢谢!

好吧

,如果它导航到 TestPage ,这意味着条件编译符号未正确定义,或者您正在运行该应用程序的 WP7 版本......似乎是这种情况,因为您的启动项目是WP7版本。

试试这段代码:

if (Environment.OSVersion.Version >= new Version(8, 0))
{
    NavigationService.Navigate(new Uri("/TestPageWP8.xaml", UriKind.Relative));
}
else
{
    NavigationService.Navigate(new Uri("/TestPage.xaml", UriKind.Relative));
}

如果您将 WP7 版本作为启动项目,则此解决方案中未定义"WP8"编译符号,您将导航到 TestPage.xaml。
如果要导航到TestPageWP8.xaml,则需要将WP8项目设置为启动项目。
还要确保编译符号 WP8 在您的 WP8 项目中实际定义 - 右键单击该项目,转到"属性"并检查"生成"选项卡,如果在"SILVERLIGHT;WINDOWS_PHONE"符号。

使用MangoPollo库中的此示例代码,您可以创建自己的SpeechSynthesizer

Type taskDataType = Type.GetType("Microsoft.Phone.Tasks.MapsTask, Microsoft.Phone");
object task = taskDataType.GetConstructor(new Type[] {}).Invoke(null);
Utils.SetProperty(task, "SearchTerm", SearchTerm);
if (ZoomLevel > 0)
    Utils.SetProperty(task, "ZoomLevel", ZoomLevel);
Utils.SetProperty(task, "Center", Center);
MethodInfo showmethod = taskDataType.GetMethod("Show");
showmethod.Invoke(task, new object[] {});

最新更新