2021-11-07 19:42:59 +01:00
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
|
|
|
|
|
namespace TINK.View
|
|
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
|
public static class ListViewAttachedBehavior
|
|
|
|
|
{
|
|
|
|
|
public static readonly BindableProperty CommandProperty =
|
|
|
|
|
BindableProperty.CreateAttached(
|
|
|
|
|
"Command",
|
|
|
|
|
typeof(ICommand),
|
|
|
|
|
typeof(ListViewAttachedBehavior),
|
|
|
|
|
null,
|
|
|
|
|
propertyChanged: OnCommandChanged);
|
2021-11-07 19:42:59 +01:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
static void OnCommandChanged(BindableObject view, object oldValue, object newValue)
|
|
|
|
|
{
|
|
|
|
|
var entry = view as ListView;
|
|
|
|
|
if (entry == null)
|
|
|
|
|
return;
|
2021-11-07 19:42:59 +01:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
entry.ItemTapped += (sender, e) =>
|
|
|
|
|
{
|
|
|
|
|
var command = (newValue as ICommand);
|
|
|
|
|
if (command == null)
|
|
|
|
|
return;
|
2021-11-07 19:42:59 +01:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
if (command.CanExecute(e.Item))
|
|
|
|
|
{
|
|
|
|
|
command.Execute(e.Item);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-07 19:42:59 +01:00
|
|
|
|
}
|