In Xamairin the Editor component doesn’t have a border on iOS. If you want to add one in the iOS project just added the following code.
using UIKit;
using WordBankEasy.iOS.Renderers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(Editor), typeof(CustomEditorRenderer))]
namespace PSC.iOS.Renderers
{
public class CustomEditorRenderer : EditorRenderer
{
protected override void OnElementChanged(
ElementChangedEventArgs<Editor> e)
{
base.OnElementChanged(e);
if(Control != null)
{
Control.Layer.BorderColor =
UIColor.FromRGB(204, 204, 204).CGColor;
Control.Layer.BorderWidth = 0.5f;
Control.Layer.CornerRadius = 3f;
}
}
}
}
Happy coding!
I was building a Xamarin solution with my components like that:

All my components (PSC.Xamarin.Controls.*) are working fine in other solutions.Always fine for Windows or UWP solutions. A problem was born when I started to deployed my solutions on iOS. When on the app I opened a page with my controls I always received an error like:

System.IO.FileNotFoundException: Could not load file or assembly 'PSC.Xamarin.Controls.BindablePicker' or one of its dependencies. The system cannot find the file specified.
I can check my references and deployment settings in all ways, it turns out there’s probably a bug in Xamarin Forms’ iOS implementation. If you use controls and only controls from a PCL or dll that does not contain other code that is called from the app, apparently Xamarin on iOS ‘forgets’ to load/deploy the assembly (or something like that). But there is a work around.
The work around is as simple as it is weird. You go the iOS app’s AppDelegate class, and you add a reference to your class(es). If this is not enough, in the FinishedLaunching function you have to add a new instance to your control as in the following example:
using System;
using System.Collections.Generic;
using System.Linq;
using PSC.Xamarin.Controls.BindablePicker;
using Foundation;
using UIKit;
namespace myInventories.iOS {
[Register("AppDelegate")]
public partial class AppDelegate :
global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate {
public override bool FinishedLaunching(UIApplication app,
NSDictionary options) {
global::Xamarin.Forms.Forms.Init();
// initialize my components
// this is a work around only for iOS.
// If you don't do that, you received an error like
// System.IO.FileNotFoundException
BindablePicker temporary = new BindablePicker();
Xamarin.FormsMaps.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
}
}
Happy coding!
If you have a new Xamarin Project and you want to add an advertising, the simple way it is to use Google Admob. This implementation is only for Android and iOS.
One of the first things people think about when developing for a new platform / using a new technology is monetization; and in my case the question is: how easy is it to integrate AdMob? For Xamarin Forms the answer would be: “It depends” – it depends on luck & on the complexity of what you want to achieve; but I will detail this as we move along.
The first thing you need to do is add the required components to your projects. For this walktrough I will be using Visual Studio but it should be relatively the same when using Xamarin Studio. Here, things go separate ways for each of the platforms:
- for Android – add the Google Play Services component
- for iOS – add the AdMob component
- for Windows Phone – download the SDK from here and add it as a reference
By now, you Android project should no longer be building & you should be receiving a COMPILETODALVIK : UNEXPECTED TOP-LEVEL error. To fix that, go into your Droid project properties, select the Android Options tab and then under Advanced modify the value for the Java Max Heap Size to 1G. Your project should now build without any errors.
Next, inside your shared / PCL project add a new Content View and call it AdMobView. Remove the code generated inside it’s constructor & it should look like this:
public class AdMobView : ContentView
{
public AdMobView() { }
}
Add this new view to your page. In XAML you can do it like this:
<controls:AdMobView WidthRequest="320" HeightRequest="50" />
Make sure NOTHING interferes with the control. By nothing I mean – overlapping controls, page padding, control margins / spacing, etc. If you have something overlapping the ad control, ads will not display & you won’t receive an error, so be careful.
Android
Add a new class called AdMobRenderer with the code below. Make sure to keep the ExportRenderer attribute above the namespace, otherwise the magic won’t happen.
using WordBankEasy.Droid.Renderers;
using WordBankEasy.Views.AdMob;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(AdMobView), typeof(AdMobRenderer))]
namespace WordBankEasy.Droid.Renderers {
public class AdMobRenderer : ViewRenderer<AdMobView, Android.Gms.Ads.AdView> {
protected override void OnElementChanged(ElementChangedEventArgs<AdMobView> e) {
base.OnElementChanged(e);
if (Control == null) {
var ad = new Android.Gms.Ads.AdView(Forms.Context);
ad.AdSize = Android.Gms.Ads.AdSize.Banner;
ad.AdUnitId = "ca-app-pub-4381168884554284/2250461656";
var requestbuilder = new Android.Gms.Ads.AdRequest.Builder();
ad.LoadAd(requestbuilder.Build());
SetNativeControl(ad);
}
}
}
}
Next, you need to modify your AndroidManifest.xml file to add the AdActivity & required permissions for displaying ads: ACCESS_NETWORK_STATE, INTERNET; just like in the example below (see also http://puresourcecode.com/dotnet/post/Android-required-permissions).
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="15" />
<application>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" />
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
That’s it. Your Android build should now display ads inside the AdMobView content view.
iOS
This, I haven’t got the chance to test yet as I don’t have a Mac around but people say it works, so I’ve added it for reference. Same as before, just add a new class called AdMobRenderer and copy-paste the code below but before you have to add a component.
In your iOS project click on “Components” (as in the picture)

and click on “Get More Components…”. Then search admob and install it.

using Xamarin.Forms;
using CoreGraphics;
using Xamarin.Forms.Platform.iOS;
using UIKit;
using WordBankEasy.Views.AdMob;
using WordBankEasy.iOS.Renderers;
using Google.MobileAds;
[assembly: ExportRenderer(typeof(AdMobView), typeof(AdMobRenderer))]
namespace WordBankEasy.iOS.Renderers {
public class AdMobRenderer : ViewRenderer {
const string AdmobID = "ca-app-pub-4381168884554284/5843056458";
BannerView adView;
bool viewOnScreen;
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.View> e) {
base.OnElementChanged(e);
if (e.NewElement == null)
return;
if (e.OldElement == null) {
adView = new BannerView(size: AdSizeCons.Banner, origin: new CGPoint(-10, 0)) {
AdUnitID = AdmobID,
RootViewController = UIApplication.SharedApplication.Windows[0].RootViewController
};
adView.AdReceived += (sender, args) => {
if (!viewOnScreen) this.AddSubview(adView);
viewOnScreen = true;
};
adView.LoadRequest(Request.GetDefaultRequest());
base.SetNativeControl(adView);
}
}
}
}
Here you can receive an strange error like:
Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[AppDelegate window]: unrecognized selector sent to instance 0x7ffee9cdd4d0
Native stack trace:
0 CoreFoundation 0x000000010a12ed85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010a5e3deb objc_exception_throw + 48
2 CoreFoundation 0x000000010a137d3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010a07db17 forwarding + 487
4 CoreFoundation 0x000000010a07d8a8 _CF_forwarding_prep_0 + 120
5 WordBankEasyiOS 0x0000000100bc65e4 GADiTunesMetadataForFileAtPath + 4181
6 WordBankEasyiOS 0x0000000100c2d484 hasRequiredParams + 10260
7 WordBankEasyiOS 0x0000000100bc5f06 GADiTunesMetadataForFileAtPath + 2423
8 WordBankEasyiOS 0x0000000100bc1c35 GADCategories_NSURL_GADNSURLUtilities + 4438
9 WordBankEasyiOS 0x0000000100c00fde GADDispatchAsyncSafeMainQueue + 45
10 libobjc.A.dylib 0x000000010a5e4bff _class_initialize + 679
11 libobjc.A.dylib 0x000000010a5eacc5 lookUpImpOrForward + 176
12 libobjc.A.dylib 0x000000010a5f98bb objc_msgSend + 187
13 WordBankEasyiOS 0x0000000100bbe0ff GADCategories_DFPBannerView_CustomRenderedAd + 18074
14 WordBankEasyiOS 0x0000000100bbe382 GADCategories_DFPBannerView_CustomRenderedAd + 18717
15 WordBankEasyiOS 0x0000000100bbe527 GADCategories_DFPBannerView_CustomRenderedAd + 19138
16 ??? 0x000000011d368a0e 0x0 + 4785080846
17 ??? 0x000000011d36843b 0x0 + 4785079355
18 ??? 0x000000011d364d88 0x0 + 4785065352
19 ??? 0x000000011c51bbd6 0x0 + 4770085846
20 ??? 0x000000011c51b138 0x0 + 4770083128
21 ??? 0x000000011c51b138 0x0 + 4770083128
22 ??? 0x000000011c51b138 0x0 + 4770083128
Don't worry! I received the same error and I spend a lot of time to understand and fix it. There is a workaround that seems working fine.
In your iOS project, open AppDelegate.cs and add this code:
/// <summary>
/// Gets the window.
/// </summary>
/// <returns>UIWindow.</returns>
[Export("window")]
public UIWindow GetWindow() {
return UIApplication.SharedApplication.Windows[0];
}
A complete example of this class is:
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using ImageCircle.Forms.Plugin.iOS;
using UIKit;
namespace WordBankEasy.iOS {
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate {
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching(UIApplication app, NSDictionary options) {
global::Xamarin.Forms.Forms.Init();
ImageCircleRenderer.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
/// <summary>
/// Gets the window.
/// </summary>
/// <returns>UIWindow.</returns>
[Export("window")]
public UIWindow GetWindow() {
return UIApplication.SharedApplication.Windows[0];
}
}
}
After that you can start you app and see you advertising without problem. For now :)
Happy coding!
I using a Xamarin Forms ListView and I want to enable or disable the Context Actions based on a certain binding or in the code behind.
The way I found is to use BindingContextChanged in a ViewCell. I show you an example
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<ContentPage.Content>
<StackLayout>
<ListView x:Name="listDictionaries"
ItemsSource="{Binding DictionariesList}"
IsVisible="{Binding ShowList}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
HasUnevenRows="true"
IsPullToRefreshEnabled="true"
RefreshCommand="{Binding Refresh}"
SeparatorVisibility="Default"
ItemTapped="OnItemTapped"
IsRefreshing="{Binding IsBusy, Mode=OneWay}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell BindingContextChanged="OnBindingContextChanged">
<ViewCell.View>
<StackLayout>
<Grid Padding="10" ColumnSpacing="10">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding Name}" FontSize="Large"
Grid.Row="0" Grid.Column="0" />
<Label Text="{Binding Description}" FontSize="Small"
Grid.Row="1" Grid.Column="0" />
</Grid>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Then you insert in the code the following code:
/// <summary>
/// Called when binding context changed.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/>
/// instance containing the event data.</param>
private void OnBindingContextChanged(object sender, EventArgs e) {
base.OnBindingContextChanged();
if (BindingContext == null)
return;
ViewCell theViewCell = ((ViewCell)sender);
var item = theViewCell.BindingContext as DictionaryModel;
theViewCell.ContextActions.Clear();
if (item != null) {
MenuItem mn = new MenuItem();
mn.Clicked += Menu_Clicked;
mn.Text = "Delete";
mn.IsDestructive = true;
mn.CommandParameter = item.Id;
theViewCell.ContextActions.Add(mn);
}
}
private async void Menu_Clicked(object sender, EventArgs e) {
var mi = ((MenuItem)sender);
}
Happy coding!
I've just created a simple MasterDetailPage and in the code I inserted an icon for the left page with:
public MainPage() {
InitializeComponent();
BackgroundColor = Color.FromHex("#007acc");
Icon = "settings.png";
}
I tried to deploy my app on an Android emulator but I can't deploy it because Android.Content.Res.Resources+NotFoundException: Resource ID #0x0.
I checked everthing and evething seemed fine. The problem is the icon!
You have to remove Icon from the code and in the XAML page type the following code:
<ContentPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<OnPlatform.iOS>settings.png</OnPlatform.iOS>
</OnPlatform>
</ContentPage.Icon>
Happy coding!
I'm trying to debbuging my app on real device (lumia 830 with windows 10 mobile 10.0.10581.0) Developer Mode is ON on both devices (mobile and PC), but when I'm deploying my app on my device I've got an error (DEP6100 and DEP6200). Howevere i can easily emulate on emulators and my PC, couldn’t understand whats the problem.
I googled a bit and I discovered how to resolve the problem.

- Create a Registry Key in: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SirepClient] (Probably you will need to create it)
- Create a
dword
with name "DisableProtocol3"
and value 00000001
- Restart Visual Studio and try deploying the solution back again.
It's a provisional solution meanwhile a patch is included in Windows 10 mobile. We will have to consider deleting this key after that.
If you want to inspect your device, connect your device via USB and open a browser and type
https://127.0.0.1:10443
And you can watch your device in action!
Windows 10 Device – Home

Windows 10 Device – App Manager

Windows 10 Device – File Explorer

Windows 10 Device – Processes

Windows 10 Device – Performances (in real time!)

When you open Visual Studio 2015 and there is a pop windows to invite you to click on it for updating Xamarin and you click, nothing happends. There is a bug but clicking the update available popup was fixed in one of the recent releases. You can manually update in the Options menu under Tools.
As for the errors, I get those all the time. Support packages can often be a problem. Update to the latest XF package. Try deleting bin, obj, and the contents of packages folders and rebuild.
