0
votes

Basically, what i have is one solution with two projects targeting Windows Phone 7 and Windows Phone 8. I have linked the pages and classes from my WP7 project to WP8 project (add as link), also each project contains two separate pages TestPage.xaml and TestPageWP8.xaml.

In the WP8 project i have added additional Conditional compilation symbols WP8. So in my MainPage i have something like:

        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   
        }

The problem is that i can not open TestPageWP8, the application always opens TestPage

My StartUp Project is WP7, i have Nokia Lumia 920 and 610. I am missing something but what?

Thank you!

4
On a side note, using conditional compilation is not the best practice. Try using a proper MVVM approach, it will avoid a lot of headaches.danielrozo
i will keep that in mindSwift Sharp
There's a great tutorial on the Nokia Developer wiki which covers WP7, WP8 and Win8 code sharing within the same solution.Neil Turner

4 Answers

1
votes

Well, if it navigates to TestPage, it means either that the conditional compilation symbol wasn't properly defined, or that you're running the WP7 version of the app... Which seems to be the case since your startup project is the WP7 version.

1
votes

Try this code:

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));
}
1
votes

If you have as a startup project the WP7 version, then the "WP8" compilation symbol is not defined in this solution and you'll navigate to the TestPage.xaml.
If you want to navigate to TestPageWP8.xaml, you need to set as the startup project the WP8 project.
Also make sure the compilation symbol WP8 is actually defined in your WP8 project - right click the project, go to Properties and check the Build tab, if WP8 is defined next to the "SILVERLIGHT;WINDOWS_PHONE" symbols.

1
votes

Using this example code from MangoPollo library, you can make your own SpeechSynthesizer library

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[] {});