Created
January 30, 2020 15:41
-
-
Save grimorde/4c94fd77339fa39418952b36b488cdf4 to your computer and use it in GitHub Desktop.
Code behind for the modal control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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