Created
February 4, 2019 23:10
-
-
Save rdelrosario/30d652840462096bb8fe1f848729627c to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Windows.Input; | |
using Xamarin.Forms; | |
namespace KeyboardOptionsSample | |
{ | |
public class CustomEditor : Editor | |
{ | |
public static BindableProperty HasExtraOptionsProperty | |
= BindableProperty.Create(nameof(HasExtraOptions), typeof(bool), typeof(CustomEditor), false); | |
public bool HasExtraOptions | |
{ | |
get { return (bool)GetValue(HasExtraOptionsProperty); } | |
set { SetValue(HasExtraOptionsProperty, value); } | |
} | |
public event EventHandler AttachMediaEvent = delegate { }; | |
public void OnAttachMediaEvent(object sender, EventArgs e) | |
{ | |
var handler = AttachMediaEvent; | |
if (handler != null) | |
{ | |
handler(this, e); | |
} | |
if (AttachMediaCommand != null && AttachMediaCommand.CanExecute(this)) | |
{ | |
AttachMediaCommand.Execute(this); | |
} | |
} | |
public static readonly BindableProperty AttachMediaCommandProperty = BindableProperty.Create(nameof(AttachMediaCommand), typeof(ICommand), typeof(CustomEditor), default(ICommand), BindingMode.OneWay, null, OnAttachMediaCommandPropertyChanged); | |
static void OnAttachMediaCommandPropertyChanged(BindableObject bindable, object oldValue, object newValue) | |
{ | |
var source = bindable as CustomEditor; | |
if (source == null) | |
{ | |
return; | |
} | |
source.OnAttachMediaCommandChanged(); | |
} | |
private void OnAttachMediaCommandChanged() | |
{ | |
OnPropertyChanged("AttachMediaCommand"); | |
} | |
public ICommand AttachMediaCommand | |
{ | |
get | |
{ | |
return (ICommand)GetValue(AttachMediaCommandProperty); | |
} | |
set | |
{ | |
SetValue(AttachMediaCommandProperty, value); | |
} | |
} | |
public event EventHandler TakePhotoEvent = delegate { }; | |
public void OnTakePhotoEventEvent(object sender, EventArgs e) | |
{ | |
var handler = TakePhotoEvent; | |
if (handler != null) | |
{ | |
handler(this, e); | |
} | |
if (TakePhotoCommand != null && TakePhotoCommand.CanExecute(this)) | |
{ | |
TakePhotoCommand.Execute(this); | |
} | |
} | |
public static readonly BindableProperty TakePhotoCommandProperty = BindableProperty.Create(nameof(TakePhotoCommand), typeof(ICommand), typeof(CustomEditor), default(ICommand), BindingMode.OneWay, null, OnTakePhotoCommandChangedPropertyChanged); | |
static void OnTakePhotoCommandChangedPropertyChanged(BindableObject bindable, object oldValue, object newValue) | |
{ | |
var source = bindable as CustomEditor; | |
if (source == null) | |
{ | |
return; | |
} | |
source.OnTakePhotoCommandChanged(); | |
} | |
private void OnTakePhotoCommandChanged() | |
{ | |
OnPropertyChanged("TakePhotoCommand"); | |
} | |
public ICommand TakePhotoCommand | |
{ | |
get | |
{ | |
return (ICommand)GetValue(TakePhotoCommandProperty); | |
} | |
set | |
{ | |
SetValue(TakePhotoCommandProperty, value); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment