Skip to content

Instantly share code, notes, and snippets.

View haavamoa's full-sized avatar
📱
Mobile developer ❤️ Open Sourcerer

Håvard Moås haavamoa

📱
Mobile developer ❤️ Open Sourcerer
View GitHub Profile
@haavamoa
haavamoa / gist:450677f18a4f281858e48efe8425118d
Created May 6, 2021 10:50
Xamarin Forms Bindableproperty Live Template
public static readonly BindableProperty $property$Property = BindableProperty.Create(
nameof($property$),
typeof($type$),
typeof($classname$));
public $type$ $property$
{
get => ($type$)GetValue($property$Property);
set => SetValue($property$Property, value);
}
<ContentPage x:Class="DIPS.Xamarin.UI.Samples.Controls.Sheet.SheetPage"
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:dxui="http://dips.xamarin.ui.com"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<dxui:ModalityLayout>
<dxui:ModalityLayout.Behaviors>
<dxui:SheetBehavior Title="Awesome Sheet"
<ContentPage x:Class="DIPS.Xamarin.UI.Samples.Controls.Sheet.SheetPage"
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:dxui="http://dips.xamarin.ui.com"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<dxui:ModalityLayout>
<dxui:ModalityLayout.Behaviors>
<dxui:SheetBehavior IsOpen="{Binding Source={x:Reference OpenSheetCheckBox}, Path=IsChecked}">
<ContentPage x:Class="DIPS.Xamarin.UI.Samples.Controls.Sheet.SheetPage"
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:dxui="http://dips.xamarin.ui.com"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<dxui:ModalityLayout>
<dxui:ModalityLayout.Behaviors>
<dxui:SheetBehavior>
<ContentPage x:Class="DIPS.Xamarin.UI.Samples.Controls.Sheet.SheetPage"
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:dxui="http://dips.xamarin.ui.com"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<dxui:ModalityLayout>
<CheckBox HorizontalOptions="Center"
VerticalOptions="Center" />
<Label Text="Is visible if MyText is not empty"
IsVisible="{Binding MyText, Converter={converters:IsEmptyConverter Inverted=True}}" />
<Label Text="Is visible if MyText is empty"
IsVisible="{Binding MyText, Converter={converters:IsEmptyConverter}}" />
public class IsEmptyConverter : IValueConverter, IMarkupExtension
{
public bool Inverted { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if(!(value is string stringValue)) return false;
return Inverted ? !string.IsNullOrEmpty(stringValue) : string.IsNullOrEmpty(stringValue);
}
public class IsEmptyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if(!(value is string stringValue)) return false;
return string.IsNullOrEmpty(stringValue);
}
namespace Visit.Mobile.MarkupExtensions
{
/// <summary>
/// A string case extension that can be used in XAML with static values (like localized strings).
/// Using this is the same as using a string case converter for bindings.
/// </summary>
[ContentProperty(nameof(Input))]
public class StringCaseExtension : IMarkupExtension
{
public string Input { get; set; }