Convert Windows 8.1 project to Windows Phone 8 - c#

I have a Windows 8.1 C# project for windows store ready.
I want to make a copy of it for Windows Phone 8.
Is there any good and easy way to do this?
I use Visual Studio Ultimate (2012 and 2013).

There's no simple/automatic way to do it, but the code will be mostly compatible. The UI will probably need to be adjusted significantly.
If you target Windows Phone 8.1 WinRT you will find more of the code will work (Windows Phone 8.0 does not support WinRT, which is what Windows Store 8.1 apps use).
A possibly better way would be to create a new Universal Windows 8.1 WinRT project and copy your existing project code in, placing as much as possible in the shared project (or in class libraries), then create a new UI for the phone version (you can keep most of the actual code behind in the shared project - see my blog post here: http://grogansoft.com/blog/?p=760 - to minimise duplication. Note that this must target WP8.1, not 8.0.
If you absolutely must target WP8.0 then you may have no better option than to just copy in the code and adjust it where necessary. This will be relatively easy for a simple app, but relatively messy for a complex app that happens to use APIs that don't match up.

Well, they are different platforms, so you'll still have to adjust your code for that, but maybe converting your portable code to a portable class library will help you:
http://msdn.microsoft.com/en-us/library/vstudio/gg597391(v=vs.110).aspx

Related

Convert Existing Windows 10 UWP Application in Android

I've found a few examples, as I in a Xamarin.Native use a Windows UWP. But that would mean that I a Xamarin.Nativ in a Windows UWP Convert.
I would like convert a finished Windows UWP application to the target Android or iOS. Is that generally supported or needs my UWP application rebuild again with Xamarin?
Links:
Adding a Universal Windows Platform (UWP) App
Getting Started with Xamarin.Forms 2.0’s Windows 10 Preview
Unfortunately asfar as I know there is no converter that allows to convert UWP app to Android app straight forward.
There are few ways to make the whole process a lot much more easier (so you can create your Android app faster).
If you wrote your UWP application and separated common code that can be used in the other applications you can also use it in Xamarin.Android app - the best way is to have PCL with the common code.
It is also important which type of Xamarin app you would like to create:
1) Xamarin Forms - common UI for each app: Windows, Android and iOS.
There is one shared code that can be used by them. Remember that Xamarin Forms apps are generally speaking the best for displaying the data and they are limited with reference to platform specific functionality.
Please see below to read more:
https://docs.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/sharing_code_options/
2) Xamarin.Platfrom (so Xamarin.Android and Xamarin.iOS):
Here you can create native UI foreach of the project (Windows, Android and iOS) and access specific platform functionality.
With reference to the code - you can put common code in one PCL and have access to it from each project.
Please see this site - here you can find different Xamarin options to create cross-platfrom apps:
https://developer.xamarin.com/
Firstly, if you want a shared code, using Portable class library, you can use the same code for all the platforms including WPF, Android and iOS. First of all what you can do is convert the codes that is used again and again in the PCL (Portable Class Lirary). Once you get used to PCL, you can easily work on any platform you want.
As the Android, iOS are different from windows, a lot of .net framework functionality is not supported in PCL. Although, once you create the basics in PCL, you can integrate the class library in android as well as iOS.

System.AppDomain.CurrentDomain.GetAssemblies() in Windows 10 Universal App

I know, there is an issue with System.AppDomain.CurrentDomain.GetAssemblies() in the Portable Class Libraries. To overcome it, I have decided to extract the list of assemblies in the target application and send it to my PCL as custom objects.
This was easy when using single-platform applications (pure WinForms, pure WP 8 application, etc.). However, I cannot find any suitable replacement for the method in Windows 10 Universal apps (and the documentation for both PCLs and Win 10 Universal Apps is pretty bad, so far). The reason, why PCLs are not able to get a list of assemblies is simply because the library does not know of all the assemblies, until it is built and packed into DLL. However, that cannot be said of the Universal App, since it should run the same system (Windows 10) -> therefore, it should be the same program on both PC and Phone -> therefore, the application should know of all its assemblies already before compiling.
So, does there exist a suitable replacement for this method, or some workaround how to get all the assemblies inside the app?
EDIT: I have found this workaround, which loops through all .dll and .exe files... however, that seems extremely unreliable. Is there a cleaner/better way?

Silverlight project in Windows universal app (Runtime)

I am creating universal app, but I want to use parts of older app, wroten in Silverlight 8.1. Is there option how to make cooperate these four projects:
MyProject.Windows (Windows 8.1)
MyProject.WindowsPhone 8.1 (Windows Phone 8.1)
MyProject.Shared
MyProject.OldSilverlightCodes(Windows Phone Silverlight 8.1)
I want to avoid migrating Silverlight code to Runtime line-by-line, it is just too complex to my skills. Is possible connect them any way, maybe via some converter class?
No, you cannot include a Silverlight project in a Windows Runtime project, and there aren't any automated converters.
In general, the best way to share .Net code across multiple targets is to use a Portable Class Library. Depending on what code you have in the Silverlight project it may be straightforward to extract the shared code to a PCL and then use the same PCL in both projects.
--Rob

What is the difference between Sensors namespaces available for Windows Phone developers?

There are two namespaces available for developers on Windows Phone 8 - Microsoft.Devices.Sensors and Windows.Devices.Sensors. They are almost identical. Could someone explain the difference?
Windows.Devices.Sensors is from Windows App store libraries, use it in WP8.
The older Microsoft.Devices.Sensors is from WP7 era, before the big change with WinRT stuff etc.
Use the newer one.
There aren't meant to be any differences so far as I'm aware, it is just a migration of namespaces for newer libraries. They are deliberately similar.
Microsoft.Devices.Sensors is part of the .Net API for Windows Phone and is specifically for phone app development. Windows.Devices.Sensors is part of the Windows API for building Windows Store applications, these applications don't necessarily have to target a Windows Phone

Share dll between WP7 and WP8 application

Usually it is recommended to have two projects for both wp7 and wp8 platforms. Wp7 project contains .cs and .xaml files, and WP8 project contains links to that files.
I think that there is no reason to compile non-platform specific business logic code twice, since it can be referenced to WP8 project.
I'm thinking about following solution structure:
Business logic dll compiled for wp7 (not a PCL)
UI comliled for wp8
UI comliled for wp7
Such application can be compiled and I can deploy it to device/emulator.
The question is: will this app pass certification in Windows phone store? Or it is necessary to recompile shared dll?
UPD:
My crazy idea was born after this steps:
Create new WP7 app (WindowsPhoneApplication1)
Create class library targeted to WP7 (WindowsPhoneClassLibrary1) Use it in WindowsPhoneApplication1
Use Upgrade to WP8 menu. WindowsPhoneApplication1 will be updated to WP8, but the referenced project will be still targeted to WP7!
Such app can be deployed to WP8 devices.
Unless you use a Portable Class Library, you'll need to have separate project files, and compile separately for WP7 and WP8.
Thanks to Claus,
I made some research, and it looks like the answer is - you can use such solution.
I didn't find related information in documentation, but here is a proof from one of MSFT tech. evangelists from Netherlands: link to blogpost
The basic idea is to move all our code that can be used from both our existing Windows Phone 7 app as well as the Windows Phone 8 build, which we will add soon, to a Common project in the solution. The bad thing about this approach is that we have to create the Common project as a Windows Phone 7 class library, which will be used in our Windows Phone 8 build. I haven’t really noticed any negative impact of this decision in my existing apps, but note that you will be referencing a Windows Phone 7 library in your Windows Phone 8 build.
So it is a possible, but not the best solution.

Categories