Skip to content

Instantly share code, notes, and snippets.

View codercampos's full-sized avatar
:octocat:
Working Hard!

Carlos Campos codercampos

:octocat:
Working Hard!
View GitHub Profile
@codercampos
codercampos / Extensioins.cs
Last active May 15, 2023 21:25
Get DisplayName attribute's value from a property.
using System.ComponentModel;
using System.Reflection;
namespace YourApp.Extensions;
public class ReflectionHelpers
{
/// <summary>
/// Get's the string value of the DisplayName attribute of a property.
/// </summary>
@codercampos
codercampos / Geocode.cs
Created September 22, 2020 14:38
Basic example how to use Google's Geocode API on Xamarin Forms (and C# in general I guess).
using System.Collections.Generic;
using Newtonsoft.Json;
namespace YourApp.Models
{
/// <Summary>
/// Basic Google's geocode information model.
/// </Summary>
public class Geocode
{
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="{Binding Title}"
xmlns:converters="clr-namespace:MyApp.Converters"
xmlns:google="clr-namespace:Xamarin.Forms.GoogleMaps;assembly=Xamarin.Forms.GoogleMaps"
x:Class="MyApp.Views.MapPage">
<Frame HorizontalOptions="FillAndExpand" Visual="Material">
<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Image Source="Your_image" VerticalOptions="FillAndExpand" HorizontalOptions="CenterAndExpand" Aspect="AspectFit" />
<Label VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" HorizontalTextAlignment="Center" Text="Text" />
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command={Binding YourTapCommand} />
</StackLayout.GestureRecognizers>
</StackLayout>
</Frame>
@codercampos
codercampos / IconBitmapConverter.cs
Last active May 1, 2019 15:25
Xamarin.Forms Google Maps Plugin ItemTemplate Sample
using System;
using System.Globalization;
using Xamarin.Forms;
using Xamarin.Forms.GoogleMaps;
namespace YourNamespace.Framework.Converters
{
public class IconBitmapConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
<google:Map MyLocationEnabled="True" ItemsSource="{Binding Items}">
<google:Map.ItemTemplate>
<DataTemplate>
<google:Pin
Type="Place"
Position="{Binding Position}"
Label="{Binding Name}"
Address="{Binding FullAddress}"
Icon="{Binding Pin, Converter={StaticResource IconBitmapConverter}}">
</google:Pin>
@codercampos
codercampos / MainPage.xaml
Created September 17, 2018 01:32
Xam.Plugin.Notifier implementation on Xamarin Forms - Xamarin Latino
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:LocalNotifications" x:Class="LocalNotifications.MainPage">
<StackLayout>
<!-- Place new controls here -->
<Button x:Name="btnNotification" Text="Send Notification in 5 seconds" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage>
@codercampos
codercampos / AppDelegate.cs
Last active September 17, 2018 00:44
Ask for local notification permissions in AppDelegate
// Check for permissions
if (UIDevice.CurrentDevice.CheckSystemVersion (10, 0)) {
// Ask the user for permission to get notifications on iOS 10.0+
UNUserNotificationCenter.Current.RequestAuthorization (
UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound,
(approved, error) => {
if (approved) {
UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate ();
}
});
<?xml version="1.0" encoding="utf-8"?>
<ContentPage Title="Barcode Demo"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:BarcodeScanner"
xmlns:viewmodels="clr-namespace:BarcodeScanner.ViewModels;assembly=BarcodeScanner"
x:Class="BarcodeScanner.Views.MainPage">
<ContentPage.BindingContext>
<viewmodels:MainPageViewModel />
</ContentPage.BindingContext>
@codercampos
codercampos / ZXingPermissionRequest.cs
Last active August 28, 2018 18:03
This is an example of how to implement the OnRequestPermissionsResult on your MainActivity.cs while using the ZXing.Net.Mobile library
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
global::ZXing.Net.Mobile.Android.PermissionsHandler.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}