Xamarin.forms Prism行为-通过按钮使用EventToCommandBehavior

Xamarin.forms Prism行为-通过按钮使用EventToCommandBehavior,xamarin.forms,prism,Xamarin.forms,Prism,我正在尝试使用Prism调用ViewModel中的方法集。我将事件绑定到按钮上的CommandBehavior,但当我单击按钮时,什么也没有发生。我已经测试了我的方法,它是有效的,所以我真的认为这是我EventToCommandBehavior的问题 XAML: <controls:FloatingActionButton HeightRequest="10" WidthRequest="10" Image="ic_add.png" ButtonColor="#3BE2CA" Grid.C

我正在尝试使用Prism调用ViewModel中的方法集。我将事件绑定到按钮上的CommandBehavior,但当我单击按钮时,什么也没有发生。我已经测试了我的方法,它是有效的,所以我真的认为这是我EventToCommandBehavior的问题

XAML:

<controls:FloatingActionButton HeightRequest="10" WidthRequest="10" Image="ic_add.png" ButtonColor="#3BE2CA" Grid.Column="1" Margin="160,45,0,40">
    <controls:FloatingActionButton.Behaviors>
        <b:EventToCommandBehavior                         
             EventName="Clicked"
             Command="{Binding AddToLibraryCommand}"/>
    </controls:FloatingActionButton.Behaviors>
</controls:FloatingActionButton>
是的,我的按钮不是一个真正的按钮,它是一个FloatingActionButton,它继承了从SuavePirate的存储库下载的Button类:

我尝试将我的行为与经典按钮以及命令属性一起使用,但两者都不起作用。
有人能解释一下问题出在哪里吗


谢谢你的帮助!:)

好了,伙计们,我发现我的错误在哪里:
按钮试图在错误的类上获取我的命令,因为我的按钮位于ListView中,而此ListView更改了按钮的绑定上下文。因此,我必须手动设置按钮的BindingContext

<controls:FloatingActionButton x:Name="FAB" HeightRequest="10" WidthRequest="10"
                                                                   ButtonColor="#3BE2CA" 
                                                                   Grid.Column="1" 
                                                                   Margin="160,45,0,40" 
                                         <!-- Added this line -->  BindingContext="{Binding Source={x:Reference BookList}, Path=BindingContext}"
                                                                   Command="{Binding AddToLibraryCommand}"/>
BindingContext=“{Binding Source={x:Reference BookList},Path=BindingContext}”
Command=“{Binding AddToLibraryCommand}”/

谢谢你的帮助

既然FloatingActionButton继承了Button类,为什么不使用Command属性呢?因为它不起作用,我指的不是行为,不是原始命令。或者是的,我理解,但它不起作用^^这就是为什么我想使用事件来控制行为或者它是否以代码隐藏的方式工作?以及如何设置Xaml的viewModel?
<controls:FloatingActionButton x:Name="FAB" HeightRequest="10" WidthRequest="10"
                                                                   ButtonColor="#3BE2CA" 
                                                                   Grid.Column="1" 
                                                                   Margin="160,45,0,40" 
                                         <!-- Added this line -->  BindingContext="{Binding Source={x:Reference BookList}, Path=BindingContext}"
                                                                   Command="{Binding AddToLibraryCommand}"/>