I would like to extend CircleImage (by James Montemagno) with a Command. I know I could use the TapGestureRecognizer, but then the CircleImage will not be disabled if the Command.CanExecute = False.
I've created a control that derives from CircleImage. The binding does not work! How do I set IsEnabled if CanExecute has changed?
public class CircleImageButton : CircleImage
{
public CircleImageButton()
{
var tgr = new TapGestureRecognizer();
tgr.SetBinding(TapGestureRecognizer.CommandProperty, new Binding("Command"));
tgr.SetBinding(TapGestureRecognizer.CommandParameterProperty, new Binding("CommandParameter"));
this.GestureRecognizers.Add(tgr);
}
#region Command
/// <summary>The <see cref="Command"/> bindable property's name.</summary>
public const string CommandPropertyName = "Command";
/// <summary>Identifies the <see cref="Command"/> bindable property.</summary>
public static readonly BindableProperty CommandProperty = BindableProperty.Create(
CommandPropertyName, typeof(ICommand), typeof(CircleImageButton), default(ICommand), propertyChanged: CommandChanged);
private static void CommandChanged(BindableObject bindable, object oldvalue, object newvalue)
{
}
/// <summary>Gets or sets the value of the <see cref="Command"/> property.</summary>
public ICommand Command
{
get => (ICommand)GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}
#endregion
#region CommandParameter
/// <summary>The <see cref="CommandParameter"/> bindable property's name.</summary>
public const string CommandParameterPropertyName = "CommandParameter";
/// <summary>Identifies the <see cref="CommandParameter"/> bindable property.</summary>
public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(
CommandParameterPropertyName, typeof(object), typeof(CircleImageButton), default(object));
/// <summary>Gets or sets the value of the <see cref="CommandParameter"/> property.</summary>
public object CommandParameter
{
get => (object)GetValue(CommandParameterProperty);
set => SetValue(CommandParameterProperty, value);
}
#endregion
}