GET Code sharing between platforms WP7, WP8, Win8. The basics / Sudo Null IT News FREE
Rather often, you have to porthole an existing practical application to other platforms operating theatre initially compose it for several platforms at in one case. In this article, we will consider the fundamental principle of code sharing specifically for three platforms, but the principles described are applicable for developing ill-natured-platform applications on other platforms, for example, using Xamarin.
Since the substantial was quite voluminous, I decided to rent the article into two parts. Nowadays we will consider the basics of joint for beginners, and if you already have basic skills, you can safely skip this article and wait for the side by side, where in practice we will consider more complex scenarios of code joint.
And straightaway I volition talk of deuce main ways of share-out codification: linking files and a library with common code. We will consistently think both approaches, the chief advantages and disadvantages of each of them.
0. Copying
Of class, you cannot showtime with linking without saying a few words about another popular way of "sharing" code - copying. Copying and modifying code for a specific political program is the easiest way to "share", and most likely in some places we volition partially exercise this approach. But we will not consider it as the main principle of share-out due to the fact that it has to a greater extent minuses than pluses. Advantages of the approach: we quickly get working code for another platform and at the same time, our changes can nohow affect the main platform. Cons: maintenance is expensive, because you have to make the same type of changes already in each copy for each platform.
1. Linking
The easiest, and perhaps the most favourite agency to indite hybrid-platform applications is to connection files. Ofttimes, when we already possess a ready-made application for WP7 and want to get the synoptical application for WP8 (Oregon the other way around), there is a big temptation to just reuse the existing code and not make whatsoever changes to the existing application architecture (if the computer architecture was not plain for this )
Let's take a calculate at this approach gradually.
For example, Army of the Righteou's create a real simple WP8 application and add together the classic "estimator" along the of import Thomas Nelson Page (MainPage.Xaml) - deuce text W. C. Fields for entering Numbers, an addition button and a field of view for displaying the result.
< StackPanel > < TextBlock Text = "A" Style = "{StaticResource PhoneTextLargeStyle}" > </ TextBlock > < TextBox x:Public figure = "TextBoxA" Text = "" > </ TextBox > < TextBlock Text = "B" Style = "{StaticResource PhoneTextLargeStyle}" > </ TextBlock > < TextBox x:Name = "TextBoxB" Text = "" > </ TextBox > < Button Placid = "Summ" Click = "ButtonBase_OnClick" > </ Button > < TextBlock x:Name = "TextBlockResult" Text = "" Style = "{StaticResource PhoneTextLargeStyle}" > </ TextBlock > </ StackPanel >
And C # code
private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { var valueA = Int32.Parse(TextBoxA.Text); var valueB = Int32.Parse(TextBoxB.Text); TextBlockResult.Text = (valueA + valueB).ToString(); }
Now we need to add a new contrive for WP7 to Solultion (File in - Add up - Novel project - Windows Phone App - Windows Phone 7).
After that, you must remove MainPage.xaml from the WP7 project and add a linkup to MainPage.xaml from the WP8 throw.
In the context menu on the WP7 see (right-dawn), choice Add - Existing Item.
Future, in the project folder for WP8, we find the MainPage.xaml lodge (only this file, the .cs file volition be added mechanically) and select Tot As Link.
Ultimately, you should get something like this in your project:
Mostly, we got a project with a common code, and in the same way we can link, if necessary, also pictures or app.xaml. Now we can take in changes to the project (for example, add number entry substantiation) and get these changes at one time in both projects.
I besides recommend that the properties specify the duplicate namespace for both projects.
Sooner or later, we wish face the features of each political program. We can single out these features using compilation symbols exploitation the #If / #else /
0 Response to "GET Code sharing between platforms WP7, WP8, Win8. The basics / Sudo Null IT News FREE"
Post a Comment