behaviors
behaviors copied to clipboard
Cannot assign property "Actions"
Hi,
I've been using Behaviors without a problem until Xamarin.Forms v3.0. When I updated to Xamarin Forms v3.0, I got the below exception
Cannot assign property "Actions": Property does not exist, or is not assignable, or mismatching type between value and property
MyView.xaml
<ContentPage.Behaviors>
<behaviors:EventHandlerBehavior EventName="Appearing">
<behaviors:InvokeCommandAction Command="{Binding PageAppearingCommand}" />
</behaviors:EventHandlerBehavior>
</ContentPage.Behaviors>
MyViewModel.cs
public ICommand PageAppearingCommand => new Command(async () =>
{
await PageAppearingAsync();
});
I have the same issue too. Using the sample from this repo, with Xamarin.Forms v2.5.1.527436, everything works like a charm. As soon as I update it to 3.0.0.446417 (in all the projects), I get the "Cannot assign property Actions" error (even after a clean & rebuild).
Thanks for letting me know. I'll look into it.
Same for me since few days and update.
A temporary fix, to unblock people, is to explicitly declare an ActionCollection
around the actions:
<ListView x:Name="listView" ItemsSource="{Binding People}">
<ListView.Behaviors>
<behaviors:EventHandlerBehavior EventName="ItemSelected">
<behaviors:ActionCollection>
<behaviors:InvokeCommandAction Command="{Binding ItemSelectedCommand}" Converter="{StaticResource SelectedItemConverter}" />
<behaviors:InvokeCommandAction Command="{Binding OutputAgeCommand}" Converter="{StaticResource SelectedItemConverter}" />
</behaviors:ActionCollection>
</behaviors:EventHandlerBehavior>
</ListView.Behaviors>
</ListView>
In the meantime, I'll work on fixing this.
This is now fixed, but I'm taking the opportunity to add a couple of extra bits of new functionality, so it'll be the end of the week before updated source code/NuGet is pushed live.
This is now fixed in v1.4.0 of the NuGet package.
~~I know this issue is closed, but I'm still having exactly the same problem, using 1.4.0 and Xamarin.Forms 3.1.0.637273. The given work around still works, so not blocked.~~
Seems I was too hasty in my previous assertion, cleaning the project and restarting VS seems to have sorted things out
Sorry, it seems that I can't get it work. Everything compiles, but the commands don't react to the events, e.g. the Appearing event doesn't fire the command I've bound to it.
@sgrassie
Have you get a small repo case for this (ZIP ideally)?
I've just created two new projects:
- .NET Standard based Forms app.
- PCL based Forms app.
In both cases I was able to install v1.4 of the Behaviors library, and use it to invoke commands in view models.
Without a firm repo case there's nothing more I can do about this.
I seem to be getting the same problem in a .NETStandard project with Xamarin Forms 3.2. I will post a repo reproducing the issue when I can.
@sgrassie I have the same issue. Were you able to fix it?