Custom editor render for Xamarin on iOS

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!

Read More

Preserve data when deploying Xamarin.Android app

By default all your data from your previous runs is deleted when you’re deploying an Xamarin.Android app. In many cases you don’t want the data to be deleted. Visual Studio To preserve data go to Tools -> Options -> Xamarin -> Android Settings and check “Preserve application data/cache on device between deploys”. Xamarin Studio To preserve data go to Tools -> Options -> Android and check “Preserve data/cache between application deploys”. Happy coding!

Read More

“System.IO.FileNotFoundException” using controls from another assembly in Xamarin Forms on iOS.

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…

Read More

What is the difference between Xamarin.Form’s layout options?

In Xamarin.Forms every View has the two properties HorizontalOptions and VerticalOptions. Both are of type LayoutOptions and can have one of the following values: LayoutOptions.Start LayoutOptions.Center LayoutOptions.End LayoutOptions.Fill LayoutOptions.StartAndExpand LayoutOptions.CenterAndExpand LayoutOptions.EndAndExpand LayoutOptions.FillAndExpand Apparently it controls the view’s alignment on the parent view. But how exactly is the behavior of each individual option? And what is the difference between Fill and the suffix Expand? Theory The structure LayoutOptions controls two distinct behaviors: Alignment: How is the view aligned within the parent view? Start: For vertical alignment the view is moved to…

Read More

Custom ContextAction with Xamarin Forms

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=”https://xamarin.com/schemas/2014/forms” xmlns:x=”https://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>…

Read More

Android.Content.Res.Resources+NotFoundException: Resource ID #0x0

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!

Read More

Visual Studio updates Xamarin

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.

Read More

How to update the data in listview in Xamarin.Forms?

First you add a new class as a ViewModel like: public class RoomViewModel : BaseViewModel { [here following code] } If you don’t have BaseViewModel try to download from nuget Refractored.MvvmHelpers. Then in your class define an observable collection like public ObservableCollection<RoomRecommandation> _roomSuggestionList = new ObservableCollection<RoomRecommandation>(); public ObservableCollection<RoomRecommandation> Recommendations { get { return _roomSuggestionList; } } In your ContentPage add a listview like: <ListView ItemsSource="{Binding Recommendations}"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <Grid Padding="10" RowSpacing="10" ColumnSpacing="10"> <Grid.RowDefinitions> <RowDefinition Height="" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <controls:CircleImage…

Read More

Xamarin Forms MasterDetail Page Navigation Recipe

In this recipe I will show you how to add a hamburger menu to your Xamarin Forms application using the MasterDetailPage class. The Xamarin.Forms MasterDetail Page consists of one page for the master and one or more pages for the detail. When used for the main navigation, as in this recipe, we will have a single master page and 4 detail pages. The code for this recipe comes from the Xamarin Forms CRM sample. I have simplified and streamlined the code, and a full Xamarin Studio solution is included at…

Read More