Posts

Showing posts with the label xamarin

Xamarin, redirect to page if status code is not Ok

Xamarin, redirect to page if status code is not Ok I have REST API that returns if user exists or not by email. If user exists and I am getting back status OK from API all works fine, but when API response with 404 my app crash. I can't figure out how to check if status is ok or not before app crash and redirect user to register page in case user is not found by API. Here is code that makes request to api: string getuserUrl = $"https://localhost:99282/api/users/{email}"; var client = new HttpClient(); var uri = new Uri(getuserUrl); var result = await client.GetStringAsync(uri); var userResult = JsonConvert.DeserializeObject<User>(result); return userResult; 1 Answer 1 You can use below code to identify whether the API call is success or not. String URL = "https://localhost:99282/api/users/{email}"; using (HttpClien...

The type or namespace name 'Xamarin' missing in xamarin studio

The type or namespace name 'Xamarin' missing in xamarin studio I'm getting this error "MyAppApp.cs(7,7): Error CS0246: The type or namespace name 'Xamarin' could not be found (are you missing a using directive or an assembly reference?) (CS0246)". i'm using Xamarin studio to make cross platform app via Xamarin.Forms but whenever i build the basic form project i get this error don't know why.I'm new in xamarin.Help me if someone know the answer. Here is the code of app.cs: using System; using Xamarin.Forms; //This is the line where error occurs namespace FIrstFormProject { public class App { public static Page GetMainPage () { return new ContentPage { Content = new Label { Text = "Hello, Forms !", VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand, }, }; } } } ...

TKCustomMap Version Conflict

TKCustomMap Version Conflict This issue has been reported on GitHub here - https://github.com/TorbenK/TK.CustomMap/issues/325 Has anyone else has struggled with this? I was stoked to find this nuget package because it does exactly what I'm looking for but it needs Places and some other GooglePlayServices installed and I can't install them because of this conflict. I'm also not sure if uninstalling TK.CustomMap and then installing the Play Services would even help because the person who reported the issue on GitHub said- I converted my app to .net 2.0 and had to use the newest Google play services 60.1142.1 for AdMob to work. It wouldn't install until I uninstalled TK.CustomMap, and now TK.CustomMap won't reinstall because it only want to use GooglePlayServices 42.1021.1 Severity Code Description Project File Line Suppression State Error NU1107 Version conflict detected for Xamarin.GooglePlayServices.Tasks. Reference the package directly from the project to resolve t...

client certificate with NSUrlSessionDelegate in xamarin

client certificate with NSUrlSessionDelegate in xamarin I want to implement client certificate authentication in my xamarin app. On top of that I am using a custom Certificate Authority (CA) and TLS 1.2. Until now I managed to get it running using android, UWP and WPF. The only platform missing is ios. Here is my NSUrlSessionDelegate: public class SSLSessionDelegate : NSUrlSessionDelegate, INSUrlSessionDelegate { private NSUrlCredential Credential { get; set; } private SecIdentity identity = null; private X509Certificate2 ClientCertificate = null; private readonly SecCertificate CACertificate = null; public SSLSessionDelegate(byte caCert) : base() { if (caCert != null) { CACertificate = new SecCertificate(new X509Certificate2(caCert)); } } public void SetClientCertificate(byte pkcs12, char password) { if (pkcs12 != null) { ClientCertificate = new X509Certificate2(pkcs12, new string(passw...

Different look/style for specific item on BottomNavigationMenu

Image
Different look/style for specific item on BottomNavigationMenu I am currently building a Xamarin Android application, and I am trying to customize the BottomNavigationView. I would like to be able to change the style of a specific menu item in the BottomNavigationView from the following: To this style: I have had a look at the following question: Different look/style for specific menu item on ActionBar but it seems more targeted towards the action bar rather then the bottom navigation. I'm guessing this would either need a custom control implemented or use of reflection to achieve the desired result? Any third-party libraries that implement this sort of functionality, aren't particularly helpful as majority of them are written for native android and not xamarin. Any help in either Xamarin C# or Native Java (that I could convert) would be great thanks. Currently I tried setting a custom action layout on the menu item programmatically: var nav = FindViewById<BottomNavigationVi...

How to change ListView item text color in Xamarin.Android?

Image
How to change ListView item text color in Xamarin.Android? I have a simple ListView like below : - <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/asimplelistView1" /> I am binding this ListView by array ArrayAdapter using: ArrayAdapter<string> arrayAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleExpandableListItem1,mItems); My app secondary text color is white(#FFFFFF) and theme is android:Theme.Material.Light.. My problem is: I need to change item text color to gray because items text color is not visible on white background. In Java we can do like below: // Create a List from String Array elements List<String> fruits_list...

Xamarin.Forms DataBinding not working

Xamarin.Forms DataBinding not working I know that this question has been asked so many times before, but every situation is kinda 'unique', let's put in that way. My environment is Visual Studio 15.7.4, using all the Nuget packages (Xamarin.Forms above all) updated to the latest version. The problem is that I created a simple binding test app, and binding doesn't work anymore! I already created an Android app with Xamarin.Forms some time ago and it all worked just fine. Now all the bindings works like "OneTime", setting only once at beginning and not updatng in the UI (but still updating the data in the main ViewModel). I would like to know if it a general Xamarin problem, or is it just me doing something wrong. I already tried out everything I could, but nothing changed. Here is the complete code (To test, create a Xamarin.Forms app with "Shared Project" as option; I usually put all the logic app code in the shared part of the project): App.cs names...

object reference not set to an instance of an object upon creating a new Android project

Image
object reference not set to an instance of an object upon creating a new Android project I get this when I want to create a new Android project. 1 Answer 1 Make sure Android Studio is not installed on your computer. If it is, uninstall it and run the Visual Studio installer again until all Android SDK errors go away. Android Studio Android SDK Make sure Visual Studio is closed and install the most recent stable version of Xamarin for Visual Studio . I found it here: https://store.xamarin.com/account/my/subscription/downloads. (Trying to install it through VS didn't work for me under Tools -> Android -> Settings -> Xamarin for Visual Studio Updates.) Make sure you have Java SDK version 7 installed on your machine. You also must use the 32-bit version even if you have a 64-bit machine. This was key! Java SDK Install the Android SDK . Standalone version , not Android Studio + Android SD...