behaviors icon indicating copy to clipboard operation
behaviors copied to clipboard

Cannot assign property "Actions"

Open ebicoglu opened this issue 6 years ago • 11 comments

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();
});

image

ebicoglu avatar May 09 '18 13:05 ebicoglu

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).

marcominerva avatar May 09 '18 13:05 marcominerva

Thanks for letting me know. I'll look into it.

davidbritch avatar May 09 '18 16:05 davidbritch

Same for me since few days and update.

MaxenceMax avatar May 14 '18 12:05 MaxenceMax

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.

davidbritch avatar May 14 '18 13:05 davidbritch

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.

davidbritch avatar May 14 '18 15:05 davidbritch

This is now fixed in v1.4.0 of the NuGet package.

davidbritch avatar May 18 '18 09:05 davidbritch

~~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

sgrassie avatar Jul 25 '18 10:07 sgrassie

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 avatar Jul 25 '18 12:07 sgrassie

@sgrassie

Have you get a small repo case for this (ZIP ideally)?

davidbritch avatar Jul 26 '18 09:07 davidbritch

I've just created two new projects:

  1. .NET Standard based Forms app.
  2. 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.

davidbritch avatar Aug 10 '18 13:08 davidbritch

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?

UnreachableCode avatar Nov 13 '18 15:11 UnreachableCode