Xamarin forms, UWP Windows 10 App, TitleBar and Status bar customization

microsoft xamarin heros c# iOS Android UWP

Customize the title bar of your Universal App for Windows 10 is quite easy, but you need to write different code for PC and Mobile. The class that allows you to customize the title bar: when running on a PC is called TitleBar when running on a Mobile is called StatusBar Before to call the API you first need to check if it exists (true if you are running on that platform): //PC customization if (ApiInformation.IsTypePresent( “Windows.UI.ViewManagement.ApplicationView”)) { var titleBar = ApplicationView.GetForCurrentView().TitleBar; if (titleBar != null) { titleBar.ButtonBackgroundColor = Colors.DarkBlue;…

Read More

An error occurs with MobileCenter for Xamarin iOS

I added Microsoft Mobile Center to my project after creating the app there. On MobileCenter documentation you can know the Install Identifier for your application (MobileCenter documentation is here). System.Guid installId = MobileCenter.InstallId; This function is working fine if you have Android or iOS 10. With iOS less than 10 an error occurs: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). and the StackTrace is similar to at System.Guid+GuidResult.SetFailure (System.Guid+ParseFailureKind failure, System.String failureMessageID, System.Object failureMessageFormatArgument, System.String failureArgumentName, System.Exception innerException) [0x00030] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.4.0.123/src/mono/mcs/class/referencesource/mscorlib/system/guid.cs:198 \n at System.Guid+GuidResult.SetFailure (System.Guid+ParseFailureKind failure, System.String failureMessageID)…

Read More

Happy 15th Birthday .NET!

Today marks the 15th anniversary since .NET debuted to the world. On February 13th, 2002, the first version of .NET was released as part of Visual Studio.NET. It seems just like yesterday when Microsoft was building its “Next Generation Windows Services” and unleashed a new level of productivity with Visual Studio.NET. Since the beginning, the .NET platform has allowed developers to quickly build and deploy robust applications, starting with Windows desktop and web server applications in 2002. You got an entire managed framework for building distributed Windows applications, ASP.NET was…

Read More

How do I extract text that lies between two strings?

My initial problem was to extract from a SQL string generated by MySql, all fields. I had a string like 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 INSERT INTO `inventoryapp`.`inventory_keys` (`Id`, `PropertyId`, `AppointmentId`, `SectionType`, `KeysDescription`, `FobsWorking`, `EntryCodes`, `AlarmCodes`, `Notes`, `Version`, `CreatedDate`, `CreatedBy`, `UpdatedDate`, `UpdatedBy`, `IsDeleted`) VALUES (<{Id: }>, <{PropertyId: }>, <{AppointmentId: }>, <{SectionType: }>, <{KeysDescription: }>, <{FobsWorking: }>, <{EntryCodes: }>, <{AlarmCodes: }>, <{Notes: }>, <{Version:…

Read More

It’s a Good Day to Be a C# Developer

Recently at Connect(), Microsoft made a slew of new announcements. First, the public availability of Visual Studio 2017 Release Candidate. This just isn’t a new version of the signature developer tool, it also includes the latest bits for C# 7.0. Second, Google announced they were joining the .NET Foundation. This means that Google, technically a competitor of Microsoft, wants to be actively involved in the evolution of .NET (and indirectly C#). Third, the first public release of Visual Studio for Mac. As a native environment, Visual Studio for Mac will…

Read More

Migrate SQLite to MySQL

I’m developing a huge app made with Xamarin Forms in my company. A problem was to create all tables in the device with SQLite to the main database MySql. I found a way to create all tables quickly with a tool called SQLite to MySQL. SQLite-to-MySQL is a powerful and reliable tool to convert SQLite databases to MySQL, MariaDB or Percona format. The program has high performance due to direct connection to source and destination databases (it does not use ODBC or any other middleware software). Command line support allows…

Read More

Xamarin Forms and Google Mobile Ads for iOS: update

In my previous post I explaind how to add on your application advertising. In those days Xamarin has removed from the Component Store the component called Google Mobile Ads for iOS. Now you have to install another component called Firebase AdMob for iOS. After installed this component you can see in your Output window a similar info without see an advert in your app: 2016-11-18 11:28:14.853 WordBankEasy.iOS[11103:2250070] <Google> You must set the rootViewController property of <GADBannerView: 0x1034702c0; frame = (-10 0; 320 50); clipsToBounds = YES; layer = <CALayer: 0x174e39d40>>…

Read More

Convert Hex Color Code to Brush/SolidColorBrush in XAML App

microsoft xamarin heros c# iOS Android UWP

To set the background color of an object in .NET XAML, you will need to set the Brush object type. To create a Brush object from a hexadecimal color code, use the following. //input ex: #dcdcdc public static Windows.UI.Xaml.Media.SolidColorBrush GetColorFromHex(string hexaColor) { return new Windows.UI.Xaml.Media.SolidColorBrush( Windows.UI.Color.FromArgb( 255, Convert.ToByte(hexaColor.Substring(1, 2), 16), Convert.ToByte(hexaColor.Substring(3, 2), 16), Convert.ToByte(hexaColor.Substring(5, 2), 16) ) ); } Happy coding!

Read More

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

Start Edge Animate when is in the screen

I’ve come across a few sites that will tie window scrolling with animation. When used in a subtle, small fashion, this is kind of cool. When used to change large portions of the view or really screw with scrolling, I detect it. Like most things, it all comes down to how you use it I suppose. But I was thinking recently – how can we do this with Edge Animate? Change edgePreload.js In a file calles something_edgePreload.js you find a line similar to the follow: if (AdobeEdge.bootstrapLoading) { signaledLoading =…

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

Xamarin Studio: complete uninstall on Mac

Remove these directories: /Applications/Xamarin Studio.app /Developer/MonoTouch /Developer/MonoAndroid /Library/Frameworks/Mono.framework /Library/Frameworks/Xamarin.Mac.framework /Library/Frameworks/Xamarin.Android.framework Locations in your user directory: ~/Library/Caches/Xamarin ~/Library/Caches/XamarinStudio-4.0 ~/Library/Developer/Xamarin ~/Library/Developer/XamarinStudio ~/Library/Logs/Xamarin ~/Library/Logs/XamarinStudio-4.0 ~/Library/Preferences/Xamarin ~/Library/Preferences/XamarinStudio-4.0 ~/Library/Xamarin ~/Library/Xamarin.Mac ~/Library/MonoTouch ~/Library/MonoAndroid ~/Library/XamarinStudio-4.0 That’s all there is afaik.

Read More

ASP.NET LinkButton: children disappears after postback

I have a LinkButton with image and label inside it or tags i and span as in the following picture. The code in the page is: <asp:LinkButton ID="LinkButton1" runat="server"> <i class="glyphicon glyphicon-plus"></i> <span class="js-add-button" runat="server" id="Span1">Add New</span> </asp:LinkButton> After a postback everything inside the LinkButton disappeared. I’ve spent two days to understand why and the solution is very easy. <asp:LinkButton ID="LinkButton1" runat="server"> <i class="glyphicon glyphicon-plus" runat="server"></i> <span class="js-add-button" runat="server" id="Span1">Add New</span> </asp:LinkButton> The tag i doesn’t have runat="server" and for that you lost all content inside the LinkButton. Happy coding!

Read More

Remove multiple line in the same file with C#

Read the file, remove the multiple line (but it saves one of them) in memory and put the contents back to the file (overwriting) and create a backup file with the original file.   using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace DelMultiLine { class Program { static void Main(string[] args) { if (args.Count() == 0 || args.Count() > 2) { Console.WriteLine(“\nDelMultiLine (by Enrico Rossini – puresourcecode.com)”); Console.WriteLine(“———————————————————————–“); Console.WriteLine(“Remove duplicate line in a file\n”); Console.WriteLine(“Usage:”); Console.WriteLine(” delmultiline <Filename> <resultFilename>\n”); Console.WriteLine(“filename: define a full path for the file you want…

Read More

Dijkstra’s Algorithm in C# with Generics

I recently needed to to implement a shortest-path algorithm (to identify preferred domain controllers using site link costs) and I found Dijkstra’s Algorithm Path class using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DijkstraAlgorithm { public class Path<T> { public T Source { get; set; } public T Destination { get; set; } /// <summary> /// Cost of using this path from Source to Destination /// </summary> /// /// Lower costs are preferable to higher costs /// </remarks> public int Cost { get; set; } } }…

Read More

DistinctBy in Linq (Find Distinct object by Property)

public class Size { public string Name { get; set; } public int Height { get; set; } public int Width { get; set; } } Consider that we have Size Class for advertisement which is having Heigth, Width and Name as property in it. Now Requirement is I have to find out the all product with distinct Name values. Size[] adv = { new Size { Name = “Leaderboard”, Height = 90, Width = 728 }, new Size { Name = “Large Rectangle”, Height = 280, Width = 336…

Read More

Data and data access technologies

In my previous post I spoke about key layers of distributed applications. Now we will go through the most crucial layer of any distributed application, the data layer. In this part, you will be introduced to various database technologies, along with .NET-related technologies. Data can be stored in a wide range of data sources such as relational databases, files on the local filesystems, on the distributed filesystems, in a caching system, in storage located on the cloud, and in memory. Relational databases (SQL server): This is the traditional data source…

Read More