This repository was archived by the owner on Aug 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
EventArgsConverter
Mark Smith edited this page Apr 11, 2018
·
2 revisions
The EventArgsConverter
is a Xamarin.Forms IValueConverter
which is intended to be used with the EventToCommandBehavior to retrieve a single property or field from the EventArgs
class.
You must supply the property/field to retrieve:
-
PropertyName
: the name of the public .NET property or field to retrieve the value from. If this is not supplied, an exception is thrown.
This converter expects that the value
parameter will be the source of the event, and that the parameter
will be the object to retrieve the property/field from. It will use runtime reflection to find the property or field - if neither can be located, an exception is thrown.
In the following example, the TheCommand
command would be located on the BindingContext
of the associated ListView
. This will pass the tapped Item
as the parameter to the ICommand
.
<Page xmlns:inf="clr-namespace:XamarinUniversity.Infrastructure;assembly=XamU.Infrastructure"
xmlns:cvt="clr-namespace:XamarinUniversity.Converters;assembly=XamU.Infrastructure" ...>
...
<ListView.Behaviors>
<inf:EventToCommandBehavior EventName="ItemTapped" Command="{Binding TheCommand}">
<inf:EventToCommandBehavior.EventArgsConverter>
<cvt:EventArgsConverter PropertyName="Item" />
</inf:EventToCommandBehavior.EventArgsConverter>
</inf:EventToCommandBehavior>
</ListView.Behaviors>