Hello,
Hope somebody can help shed some light on this:
In Visual Studio 2013 (VS) when I create a Blank App (Xamarin.Forms Portable) Project (default settings) I experience the following:
E.g. Class System.Net.IPAddress is available in the Droid Project class MainActivity & in the App1.iOS Project class AppDelegate.cs but NOT in the App1 (Portable) project class App.cs.
Why is this so?
Answers
Probably because it's not a PCL API. You have to use it in its own project and call in PCL via DependencyService.
For example, alse System.IO has not all methods in PCL...
@AlessandroCaliaro|
Thanks for your answer!
I thought that any API Function that is available in the union of all platforms would be available in the PCL project as well: Doesn't that make sense?
I am not familiar with how to use DependencyService. I see that DependencyService provides the Register and Get methods...
How can I use DependencyService to create an instance of e.g. IPAddress in the Portable part of the project?
Could you provide an example please?
Take a look at this sample
https://developer.xamarin.com/guides/xamarin-forms/dependency-service/battery-info/
In PCL you have to create an interface, then, in every platform, you have to create a class that implement the interface.
then in PCL you can use methods calling the DependencyService
https://developer.xamarin.com/guides/xamarin-forms/dependency-service/battery-info/#Implementing_in_Shared_Code
@AlessandroCaliaro
Thanks for your pointers: I am starting to understand the DependencyService concept now!
Will read more up on it.
When any event or method triggered on some action (like button pressed) in Droid Project then is it possible to get this same event at the same time triggered in the Portable project ( in Xaml Forms) using Dependency Services?