Skip to content

Instantly share code, notes, and snippets.

@grimorde
Created January 30, 2020 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grimorde/4c94fd77339fa39418952b36b488cdf4 to your computer and use it in GitHub Desktop.
Save grimorde/4c94fd77339fa39418952b36b488cdf4 to your computer and use it in GitHub Desktop.
Code behind for the modal control
namespace XamarinModalExample.Controls
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Modal : ContentView
{
public static readonly BindableProperty ShowModalProperty
= BindableProperty.Create(nameof(ShowModal), typeof(bool), typeof(Modal), defaultValue: false, defaultBindingMode: BindingMode.TwoWay, propertyChanged: ShowModalPropertyChanged);
public static readonly BindableProperty ModalHeaderProperty
= BindableProperty.Create(nameof(ModalHeader), typeof(string), typeof(Modal), defaultValue: string.Empty, defaultBindingMode: BindingMode.TwoWay);
public string ModalHeader
{
get => GetValue(ModalHeaderProperty).ToString();
set => SetValue(ModalHeaderProperty, value);
}
public bool ShowModal
{
get => (bool)GetValue(ShowModalProperty);
set => SetValue(ShowModalProperty, value);
}
public Modal()
{
InitializeComponent();
IsVisible = false;
}
private static void ShowModalPropertyChanged(BindableObject bindable, object oldvalue, object newvalue)
{
((Modal)bindable).IsVisible = (bool)newvalue;
}
private void CloseModalBtn_OnClicked(object sender, EventArgs e)
{
ShowModal = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment