Skip to content

Instantly share code, notes, and snippets.

View jfversluis's full-sized avatar

Gerald Versluis jfversluis

View GitHub Profile
@jfversluis
jfversluis / dotnet-format-action.yml
Created July 25, 2020 08:30 — forked from rickyah/dotnet-format-action.yml
Runs dotnet-format on every PR and create a commit that fixes the formatting if it doesn't comply with your code convention
name: Format check on pull request
on: pull_request
jobs:
dotnet-format:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2.2.0
with:
fetch-depth: 0
@jfversluis
jfversluis / NoBounceRenderer.cs
Created July 10, 2020 14:58
Disable bounce effect on Xamarin.Forms CollectionView
using System;
using CollectionViewBounceSample.iOS;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(CollectionView), typeof(NoBounceRenderer))]
namespace CollectionViewBounceSample.iOS
{
public class NoBounceRenderer : CollectionViewRenderer
{
@jfversluis
jfversluis / regexnamedgroups.cs
Last active July 9, 2020 12:50
Using Regex Named Groups in C#
var azureDevOpsUrl = "https://dev.azure.com/jfversluis";
var resultUrl = "";
var azureDevOpsMatch = Regex.Match(azureDevOpsUrl, "(?<protocol>http[s]?://)(?<domainandpath>dev.azure.com/(?<accountname>[a-zA-Z]*)(.*))", RegexOptions.IgnoreCase);
if (azureDevOpsMatch.Success)
{
resultUrl = $"{azureDevOpsMatch.Groups["protocol"]}{azureDevOpsMatch.Groups["accountname"]}@{azureDevOpsMatch.Groups["domainandpath"]}";
}
Console.WriteLine(resultUrl);
<?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" x:Class="CastRadio.MainPage" xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" ios:Page.UseSafeArea="true">
<StackLayout>
<Entry Text="{Binding CastUrl, Mode=TwoWay}" />
<Button Text="Cast" Command="{Binding StartCastCommand}" />
<ListView MinimumHeightRequest="100" SelectionMode="Single" ItemsSource="{Binding CastDevices}" SelectedItem="{Binding SelectedCastDevice}">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding FriendlyName}" />
</DataTemplate>
public partial class MainPage : ContentPage
{
public string CastUrl { get; set; } = "https://icecast-qmusicnl-cdp.triple-it.nl/Qmusic_nl_live_32.aac";
public ObservableCollection<IReceiver> CastDevices { get; set; }
public IReceiver SelectedCastDevice { get; set; }
public Command StartCastCommand { get; set; }
public MainPage()
@jfversluis
jfversluis / SimplifiedGrid.xaml
Created June 4, 2020 07:26
Simplified Xamarin.Forms Grid definition
<Grid ColumnDefinitions="1*, 2*, Auto, *, 300" RowDefinitions="1*, Auto, 25, 14, 20"/>
@jfversluis
jfversluis / Grid.xaml
Created June 4, 2020 07:23
Example of a Xamarin.Forms Grid definition
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="300" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
@jfversluis
jfversluis / MainPageViewModel.cs
Last active March 30, 2020 19:36
View model for our main page
using System.Collections.ObjectModel;
using Xamarin.Forms;
namespace DataBindingScopeSample
{
public class ListModel
{
public string Title { get; set; }
public string Image { get; set; }
}
@jfversluis
jfversluis / MainPage.xaml
Last active March 30, 2020 20:20
Page with ListView with differend data binding options
<?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" x:Class="DataBindingScopeSample.MainPage" xmlns:local="clr-namespace:DataBindingScopeSample;assembly=DataBindingScopeSample" Title="Nine-Nine">
<!-- Scope is MainPageViewModel, therefore we can set the ItemsSource to its MyItems property -->
<ListView x:Name="ListOfPeople" ItemsSource="{Binding MyItems}" RowHeight="100">
<ListView.ItemTemplate>
<DataTemplate>
<!-- Here the scope is the ListModel object. That is why we can reference the Title and Image properties -->
<ImageCell Text="{Binding Title}" ImageSource="{Binding Image}">
<!-- WARNING: NOT WORKING! -->
<!-- You would expect the binding to HighFiveCommand to just
// For iOS in the AppDelegate.cs
public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions)
{
global::Xamarin.Forms.Forms.SetFlags("SwipeView_Experimental", "CarouselView_Experimental");
Forms.Init();
// The rest of the code...
}
// For Android in the MainActivity.cs