Good aftnernoon ladies and gents.
My situation is as followed:
- Portable project with a Custom Behavior in it.
- Regular Xamarin project which has a reference to the Portable project in the Shared code project.
The Behavior in question (it's based on a Custom Entry which i named Entry )
using System;
using System.Windows.Input;
using XamarinForms = Xamarin.Forms;
`
namespace ChipSoft.Mobile.Core.Presentation.Xamarin.Behaviors
{
public class CompletedEventBehavior : XamarinForms.Behavior
{
public static readonly XamarinForms.BindableProperty CommandProperty = XamarinForms.BindableProperty.Create<CompletedEventBehavior, ICommand>
(
p => p.Command,
null,
propertyChanged: OnCommandChanged
);
public ICommand Command
{
get { return (ICommand)GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}
public static void OnCommandChanged(XamarinForms.BindableObject bo, ICommand oldValue, ICommand newValue)
{
bo.SetValue(CommandProperty, newValue);
}
protected override void OnAttachedTo(Entry entry)
{
entry.Completed += OnEntryCompleted;
base.OnAttachedTo(entry);
}
protected override void OnDetachingFrom(Entry entry)
{
entry.Completed -= OnEntryCompleted;
base.OnDetachingFrom(entry);
}
void OnEntryCompleted(object sender, EventArgs args)
{
if (Command != null)
{
if (Command.CanExecute(null))
{
Command.Execute(null);
}
}
}
}
}
`
Xaml usage:
xmlns:behaviors="clr-namespace:ChipSoft.Mobile.Core.Presentation.Xamarin.Behaviors;assembly=ChipSoft.Mobile.Core.Presentation.Xamarin"
<Entry.Behaviors>
<behaviors:CompletedEventBehavior Command="{Binding LoginCommand}"/>
</Entry.Behaviors>
The LoginCommand does what it says it does
The error I am getting complete with Stacktrace:
A first chance exception of type 'System.InvalidOperationException' occurred in Xamarin.Forms.Core.DLL
Additional information: bindable not an instance of AssociatedType
at Xamarin.Forms.Behavior.Xamarin.Forms.IAttachedObject.AttachTo(BindableObject bindable)
The question is quite simple, why doesn't this work?
It is based on several posts online and it worked before we moved the Behavior itself to the portable project.
We are using the latest Xamarin.Core and Xamarin.Forms versions.