EzDev.org

Xamarin.Forms

Xamarin.Forms official home Build a Native Android UI & iOS UI with Xamarin.Forms - Xamarin use xamarin.forms to quickly design android ui & ios ui’s from a single, shared c# codebase. our api & ui design tools help app developers work efficiently.


How to use Push Notifications in Xamarin Forms

I'm an app using Xamarin>Forms targeting IOS, Android and WP 8.

I need push notifications feature in my app.

I have seen the pushsharp demos and seems promising. But all the codes I had seen is done separately for each platform.

I would like it to be done in the Xamarin.Forms project, somewhere in the App.cs so that I don't need to repeat the code for registering device, and handle how push notifications should be processed.

Any help would be greatly appreciated. Sample codes or tutorial references are welcome.

Edit : I implemented it based on Idot's answer. Here is the link for my answer.


Source: (StackOverflow)

Xamarin Forms Android App Crashes Running Debug with VS Android Emulator

I have a basic Xamarin Forms app I created. It works fine against the iOS simulator.

However when I try and run with a VS Android Emulator (5.1in Marshmallow) it crashes every time upon opening. Even when I try and run without debugging. Below is the error I keep seeing:

01-14 16:22:10.290 D/Mono    ( 1366): AOT module 'mscorlib.dll.so' not found: dlopen failed: library "/data/app-lib/App3.Droid-2/libaot-mscorlib.dll.so" not found
01-14 16:22:10.290 D/Mono    ( 1366): AOT module '/Users/builder/data/lanes/2512/d3008455/source/monodroid/builds/install/mono-x86/lib/mono/aot-cache/x86/mscorlib.dll.so' not found: dlopen failed: library "/data/app-lib/App3.Droid-2/libaot-mscorlib.dll.so" not found
01-14 16:22:10.294 D/Mono    ( 1366): Unloading image data-0x9659b010 [0xb93d5940].

I am running VS2015 + Xamarin Forms 2.0 latest and greatest.

What's going on here?


Source: (StackOverflow)

How can I create a drawer / slider menu with Xamarin.Forms?

How do I create an a slider menu using Xamarin.Forms? Is it baked in or something custom?


Source: (StackOverflow)

Xamarin Forms StackLayout: How to set width / height of children to percentages

Is there a way to create a vertical stack layout with a button that takes 30% of of the parent, and a text input that takes 70% of the parent? Something like this:

<StackLayout Orientation="Vertical">
    <Entry Height="70%"></Entry>
    <Button Height="30%">Click me</Button>
</StackLayout>

But this doesn't work. Only solution so far is creating a complete Grid item and using that. Are there no other solutions?


Source: (StackOverflow)

Camera access with Xamarin.Forms

Is anyone able to give a short, self-contained example on how to access the camera with Xamarin.Forms 1.3.x? Simply calling the native camera application and retrieving the resulting picture would be great. Displaying a live view on the Xamarin.Forms page would be awesome!

I already tried to use Xamarin.Mobile and Xamarin.Forms.Labs, but I couldn't get any solution to work on both platforms (focussing on Android and iOS for now). Most code snippets found on the web (including stackoverflow) are incomplete, e.g. not showing the implementation of an IMediaPicker object or where to anchor the method for taking pictures.


Source: (StackOverflow)

React Native v Xamarin Forms - Choosing Cross Platform App Environment [closed]

I have been looking at Xamarin Forms for building a cross platform App. We would like a framework which targets iOS, Android and Windows Phone. It seems like a nice product, but the license cost may cause us a problem with our business model and also licensing for Windows Phone development is unclear.

I have come across another framework called React Native which claims to be able to build cross platform apps. I wondered if anyone could give me an idea of its strengths and weaknesses, in particular, relative to Xamarin Forms if possible. One thing is that it uses Javascript, which may not scale well (either in terms of code maintenance or execution performance). But I would be grateful for input from anyone who has looked closer at React and has formed some objective opinions about its usefulness.

https://facebook.github.io/react-native/

Thanks.


Source: (StackOverflow)

Stick Layout in Xamarin Forms to bottom

I'm making an application in Xamarin forms but I have some trouble sticking a layout to the bottom of the device. I thought an AbsoluteLayout would work, but I cannot grasp how it works. So I made a RelativeLayout which I filled with the elements I wanted to fill but now I cannot seem to get it working on sticking to the bottom of the device at all time.

Below is a screenshot to make things hopefully a little bit more clear. I have a stacklayout which I fill with the headerlayout and the contentlayout. But if I just add the footerlayout to the stacklayout, it will not be sticked to the bottom of the page but (logically) just behind the previous child. Now I think an Absolutelayout would do the trick, but I cannot seem to grasp the functionality and the Layoutflags and bounds of it. Could someone help me out?

My application


Source: (StackOverflow)

Xamarin.Forms ListView: Set the highlight color of a tapped item

Using Xamarin.Forms, how can I define the highlight/background color of a selected/tapped ListView item?

(My list has a black background and white text color, so the default highlight color on iOS is too bright. In contrast, on Android there is no highlighting at all - up to a subtle horizontal gray line.)

Example: (left: iOS, right: Android; while pressing "Barn2")


Source: (StackOverflow)

Horizontal ListView Xamarin.Forms

Is any way to create ListView with horizontal scroll in Xamarin.Forms like image

ListView Horizontal

this is what i have done for vertical

var myListView = new ListView
{
    ItemTemplate = new DataTemplate(typeof(ImageCell))
};

Source: (StackOverflow)

The "LinkAssemblies" task failed unexpectedly

When we are trying to build a xamarin forms project in release mode, we are getting the error:

C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(5,5): Error MSB4018: The "LinkAssemblies" task failed unexpectedly.
Xamarin.Android.XamarinAndroidException: error XA2006: Reference to metadata item 'System.Void Android.Widget.AbsListView::SetSelectionFromTop(System.Int32,System.Int32)' (defined in 'Xamarin.Forms.Platform.Android, Version=1.3.3.0, Culture=neutral, PublicKeyToken=null') from 'Xamarin.Forms.Platform.Android, Version=1.3.3.0, Culture=neutral, PublicKeyToken=null' could not be resolved. ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void Android.Widget.AbsListView::SetSelectionFromTop(System.Int32,System.Int32)
   at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
   at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
   at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
   at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
   at Mono.Linker.Steps.MarkStep.ProcessQueue()
   at Mono.Linker.Steps.MarkStep.Process()
   at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
   at Mono.Linker.Pipeline.Process(LinkContext context)
   at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
   at Xamarin.Android.Tasks.LinkAssemblies.Execute()
   --- End of inner exception stack trace ---
   at Xamarin.Android.Diagnostic.Error(Int32 code, Exception innerException, String message, Object[] args)
   at Xamarin.Android.Tasks.LinkAssemblies.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext() (MSB4018) (XXX.Android)

How can we resolve this? We have tried cleaning and building again. Even closing xamarin studio and restarting it. Nothing seems to work.

We are on the latest release of xamarin forms and xamarin forms labs. The minimum android API level we are using is 17. I even tried minimum sdk version 20.

Some more details:

Xamarin Studio
Version 5.7 (build 661)
Installation UUID: f97e711d-1fe0-450f-a3bb-2d9b972ab295
Runtime:
    Microsoft .NET 4.0.30319.0
    GTK+ 2.24.22 (MS-Windows theme)
    GTK# 2.12.26

Xamarin.Android
Version: 4.20.0 (Indie Edition)
Android SDK: C:\Users\Kartik\AppData\Local\Android\android-sdk
    Supported Android versions:
        2.1    (API level 7)
        2.2    (API level 8)
        2.3    (API level 10)
        3.1    (API level 12)
        4.0    (API level 14)
        4.0.3  (API level 15)
        4.1    (API level 16)
        4.3    (API level 18)
        4.4    (API level 19)
        4.4.87 (API level 20)
        5.0    (API level 21)
Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_39
java version "1.6.0_39"
Java(TM) SE Runtime Environment (build 1.6.0_39-b04)
Java HotSpot(TM) Client VM (build 20.14-b01, mixed mode, sharing)

Build Information
Release ID: 507000661
Git revision: b70bab61da996da29045ea8ee8aed1a6faedbe78
Build date: 2015-01-05 11:27:37-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7

Operating System
Windows 6.2.9200.0 (64-bit)

Source: (StackOverflow)

How to partially cut ViewCell separator line in Xamarin Forms?

I am using ViewCell to create rows in my table settings page. I have a setting to select a Light or Dark theme.

<ViewCell Height="50">
    <StackLayout x:Name="darkTheme" VerticalOptions="FillAndExpand" Padding="20,0,20,0">
        <StackLayout Orientation="Horizontal" VerticalOptions="CenterAndExpand">
            <Label Text="Dark" XAlign="Center" FontSize="15"/>
            <Label x:Name="darkThemeCheckmark" Text="{x:Static local:FontAwesome.FACheck}" FontFamily="FontAwesome" XAlign="Center" IsVisible="false" FontSize="12" HorizontalOptions="EndAndExpand"/
        </StackLayout>
    </StackLayout>
</ViewCell>
<ViewCell Height="50">
    <StackLayout x:Name="lightTheme" VerticalOptions="FillAndExpand" Padding="20,0,20,0">
        <StackLayout Orientation="Horizontal" VerticalOptions="CenterAndExpand">
            <Label Text="Light" XAlign="Center" FontSize="15"/>
            <Label x:Name="lightThemeCheckmark" Text="{x:Static local:FontAwesome.FACheck}" FontFamily="FontAwesome" XAlign="Center" IsVisible="false" FontSize="12"/>
        </StackLayout>
    </StackLayout>
</ViewCell>

Whenever I switch from dark to light theme, there is faint light line on the left side between my rows that I can't seem to get rid of. Please refer to the images below:

enter image description here

enter image description here

In my renderer I have set the following:

tableView.LayoutMargins = new UIEdgeInsets() { Left = 20 };
cell.SeparatorInset = new UIEdgeInsets() { Left = 20 };
cell.LayoutMargins = new UIEdgeInsets() { Left = 20 };

Anyone knows how to get rid of this line?

Edit:

I wanted it to look like below: enter image description here


Source: (StackOverflow)

The "XamlCTask" task failed unexpectedly on visual studio for xamarin

When I am trying to run application on Xamarin on visual studio, I am getting error as mentioned below and not able to run the application on device or emulator:

The "XamlCTask" task failed unexpectedly.
Microsoft.Cci.Pdb.PdbDebugException: Unknown custom metadata item kind: 6
   at Microsoft.Cci.Pdb.PdbFunction.ReadCustomMetadata(BitAccess bits)
   at Microsoft.Cci.Pdb.PdbFunction..ctor(ManProcSym proc, BitAccess bits)
   at Microsoft.Cci.Pdb.PdbFunction.LoadManagedFunctions(BitAccess bits, UInt32 limit, Boolean readStrings)
   at Microsoft.Cci.Pdb.PdbFile.LoadFuncsFromDbiModule(BitAccess bits, DbiModuleInfo info, IntHashTable names, ArrayList funcList, Boolean readStrings, MsfDirectory dir, Dictionary`2 nameIndex, PdbReader reader)
   at Microsoft.Cci.Pdb.PdbFile.LoadFunctions(Stream read, Dictionary`2& tokenToSourceMapping, String& sourceServerData)
   at Mono.Cecil.Pdb.PdbReader.PopulateFunctions()
   at Mono.Cecil.Pdb.PdbReader.ProcessDebugHeader(ImageDebugDirectory directory, Byte[] header)
   at Mono.Cecil.ModuleDefinition.ProcessDebugHeader()
   at Mono.Cecil.ModuleDefinition.ReadSymbols(ISymbolReader reader)
   at Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition module, ReaderParameters parameters)
   at Mono.Cecil.ModuleReader.CreateModuleFrom(Image image, ReaderParameters parameters)
   at Mono.Cecil.ModuleDefinition.ReadModule(Stream stream, ReaderParameters parameters)
   at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters)
   at Xamarin.Forms.Build.Tasks.XamlCTask.Compile()
   at Xamarin.Forms.Build.Tasks.XamlCTask.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__1.MoveNext()  MyFirstProject      

Before adding this "Xamarin.Forms.Maps" NuGet package, my application working but as I have added this suddenly application stops running and getting error.

Anybody could help me what causes this type of issue?


Source: (StackOverflow)

In Xamarin.Forms Device.BeginInvokeOnMainThread() doesn’t show message box from notification callback *only* in Release config on physical device

I'm rewriting my existing (swift) iOS physical therapy app "On My Nerves" to Xamarin.Forms. It's a timer app to help people with nerve damage (like me!) do their desensitization exercises. You have these "fabrics" (e.g. a feather) where each fabric has a 'x' second countdown. When once fabric's timer reaches 0, a message box appears saying "time's up". The user hits OK and the next fabric starts its countdown. Rinse and repeat for all fabrics in the list. Here's a video showing the workflow. Trust me on the UX in video.

Here's my sample app code demonstrating this behavior.

The DoSomethingForNow method (forgive my naming strategy) is the callback from the NotificationService (see line 65 - not enough SO rep points for direct link) that is created when the timer starts, in case the app gets background.

The specific call that is not working on Release mode on Device is at line 115

Device.BeginInvokeOnMainThread(
                async () => await ShowAlertAndWaitForUser(currentFabricCount));

The async () => await ShowAlertAndWaitForUser(currentFabricCount)) works as expected in Debug and Release configuration on iOS Simulator, and in Debug configuration on device.

However, the message box indicating time is up does not appear in Release config on the physical device. I cannot figure out why Device.BeginInvokeOnMainThread() doesn't work in Release config on device. What is going on?

Side note re using Device.StartTimer()

The reason why I switched from Device.StartTimer() to James's FrenchPressTimer solution (see jamesmontemagno/FrenchPressTimer) early on is because I need a way to cancel / stop / whatever a Device.StartTimer() in case the user needs to pause or stop the countdown on the app.

The Device.StartTimer() code works great for me on all configurations on both simulator and device and thankfully someone showed me how to cancel a Device.StartTimer (thanks!). If you want to see this working solution, check out saraford/Device-StartTimer-Working-Xamarin on github.

My specific question is why doesn't Device.BeginInvokeOnMainThread() display a message box when invoked from a notification callback in Release config on a physical device.

I've also tried the different linker combinations. No effect.


Source: (StackOverflow)

How can I run a method in the background on my Xamarin app?

Once the app is open and running I would like a background process to check a database and to make an update depending on the data in the database. I would like to make this check every one minute. I only want this to happen when the app is in the foreground and in view of the user.

Can someone give me some suggestions as to how I do this? I assume I can call a method from here but I'm not sure how to do this. Also I do not know how to stop or even if I need to manually cancel / stop the process. Would it cancel itself when the app is not in the foreground and restart when the app came back into the foreground?

public partial class App : Application
{

   protected override void OnStart()
   {
      App.DB.InitData();
      MainPage = new Japanese.MainPage();
   }

But do I need to make this run on a different thread and if so how could I do that.

Sorry if my question is not clear. Please ask and I can update if it doesn't make sense.


Source: (StackOverflow)

When to use Xamarin.Forms vs Xamarin Native? [closed]

I am in need to make a choice between Xamarin.Forms vs Xamarin native apps.

I want to go with Xamarin.Forms as UI code will be shared as well.

So what are the drawbacks of Xamarin.Forms as compared to Native.


Source: (StackOverflow)