How to include component in Xamarin / Xamarin.Forms - xamarin

How to include component in Xamarin.Forms?
Please suggest some component which supports dialog box, select pictures from library which is supported in Xamarin.Forms.
Because as per my knowledge, components can be added only to device specific project but not in common Forms project in Xamarin.Forms.
Thanks.

Option 1 (ok) - Components :
as Jason stated, create an interface in the common library.
then create wrapper implementations within each device-specific project.
like each variation to the same interface using DependencyService
your common code will talk to the right instance of that interface, after it has been automatically injected.
Option 2 (worst) - Components :
if you can, use a Shared Library for your common Forms code.
then use compiler directives (#if #endif ...) in your class to separate device-specific implementation and probably different namespaces as well.
Option 3 (best) - Non-Components :
instead of using Xamarin Components, use NuGet in your PCL/SharedLib, and get the awesome Acr.XamForms, it has a User Dialogs and a Camera/Gallery lib

There is also Forms Labs with Video & Image pickers.

Include the component in your device-specific project, then use the Xamarin Forms' DependencyService to inject that device specific behavior into your common Forms project.

Related

How to use System.Security.Cryptography in Xamarin.Forms PCL

By reference to this link https://developer.xamarin.com/api/namespace/System.Security.Cryptography/
May I know how do I include this in my Xamarim.Forms PCL project? When I include in, Visual Studio is giving error as the picture below
May I know if anybody has any idea how to solve this? Thanks.
The namespace is available both in Xamarin.iOS and Xamarin.Android. You could make platform specific implementations for both platforms and then resolve them with the DependencyService
You would have your interface for whatever you need in your PCL
public interface ICryptoService // or whatever
{
string Cipher(string stringToCipher);
string Decipher(string stringToDecipher);
}
and then implement these in your platform specific projects
using System.Security.Cryptography;
namespace MyApp.Droid
{
public class CryptoService : ICryptoService
{
// implement interface
}
}
To make the implementation visible to DependencyService you have to use the DependencyAttribute
[assembly: Xamarin.Forms.Dependency(typeof(MyApp.Droid.CryptoService)]
You can now obtain an instance in your PCL with
var cryptoService = DependencyService.Get<ICryptoService>();
and then use it. The steps for iOS are basically the same. For UWP you have to register the implementation manually, see here.
Edit:
Since it's likely that the implementation will be the same for all platforms, you could introduce a shared project and put the implementation there. All you have to do now is referencing the shared project from your iOS and Android projects.
Edit 2:
Adding a shared project to an existing Xamarin.Forms solution is quite easy. Just right-click your solution in VS, choose Add -> New Project... (I only have a german localized VS at hand at the moment, but it should be something in the lines of that). Now select Shared Project, give it a name and click OK, there will be a new shared project in your solution.
Now right-click your platform specific project and choose Add -> Reference.... The window to add a reference should open and on the left you can choose the source of the reference (Assemblys, Projects, Shared Projects, COM and Browse). Select Shared Project and then the project you just created. Any code file in your shared project will now be compiled with your platform specific project as if the code file was in the platform specific project (watch for namespaces!). Repeat for the other platform specific projects.

Accessing resources XML from another library project in Xamarin.Android

I am trying to create a Xamarin.Android Component to send to the Xamarin Component Store, and I need to bundle my Colors.xml with it, so it is accessible to everyone using my component. I am setting the build action for the Colors.xml tp "AndroidResource".
So I created an Android sample application, when I add a reference to my library project's dll, I am able to use the colors defined, my project compiles and it runs, but I get no intellisense on Xamarin Studio. So that would be a bad thing for anyone using my library, as they would not be able to even see that the colors are available to use. You can see in this picture the colors defined are not available in the suggestions box.
If I add the Colors.xml directly into my project, I get Intellisense support, like this:
Is there a way to achieve the same result above when adding just the dll reference? Did I do something wrong or Xamarin.Android/Xamarin Studio doesn't support this kind of scenario?
EDIT: To be clear, I know this is a problem with Intellisense not being able to pick up the values, but is there anything I can do to make it work?

Creating a Selection List (WearableListView)

https://developer.android.com/design/wear/patterns.html#Selection hints the use of WearableListView to create a wearable compatible ListView, but there is no details on how to actually implement it. How can I use it?
I have found a sample project in Android SDK folder (android-sdk\samples\android-20\wearable\Notifications) that has implemented this

Monodroid Layout Folder support

I'd like to use qualifiers on my layout folders as per the android documentation, but the designer in VS doesn't seem to support them. For example layout-w600dp doesn't get sent to the emulator; the default axml file from the layout folder is used.
Does anyone know if these settings are supported in Monodroid? If so, how do you make them take effect?
I think w600dp requires a certain api level to work - maybe 3.2 - see http://android-developers.blogspot.co.uk/2011/07/new-tools-for-managing-screen-sizes.html

Windows forms - circular dependency?

I am converting my C# windows forms application to a C++\CLI windows forms application.
My C# version had a circular dependency between forms. For example, the 'Main' form creates 'Form2' and shows it, and when Form2 is closed it re-shows the hidden 'Main' form by accessing the static Main form instance through Main.activeWindow (in C++ this would require a circular dependency between headers and classes). There is also much more communication between the two forms - ie. 'Form2' changing a button color in form 'Main', or updating a property.
How can I break this dependency (I just don't want to have to mess around with forward declarations and such), but still having the same functionality?
Thanks for your help,
Alex
The only way is too split the class definition into the normal .h/.cpp files. Include the declarations in the .h and the bodies in the .cpp where they can see both class definitions.

Resources