Bind Command to a template view from viewmodel xamarin prism

I use prism on the project. My problem is: i have a View OrdemServicoView and a model OrdemServicoViewModel, OrdemServicoView has a syncfusion list... inside has a DataTemplate with a some propertys pass and i can bind, but when i try use command inside template it doesnt work, the command code is in OrdemServicoViewModel... how can i do that?

OrdemServicoViewModel:

public DelegateCommand ItemSelectedCommand { get; set; }
OrdemServicoView (List):

<syncfusion:SfListView.ItemTemplate>



</syncfusion:SfListView.ItemTemplate>
In OrdemServicoCardView i try to make a button with ItemSelectedCommand binded

Answers

  • stemadostemado Member ✭✭
    edited November 2018

    Without seeing your full XAML markup, it sounds like you need to use relative source binding.

    Try:

    1. Adding an x:Name to your <syncfusion:SfListView /> so your button can reference the same ViewModel that is used by your SfListView (which I believe in this case is located in OrdemServicoViewModel)

      <syncfusion:SfListView x:Name="aUniqueName" (...) />

    2. Now set Your Binding Context for your Button Command via the Path where
      A. ItemSelectedCommand is the DelegateCommand you want fired inside of your ViewModeL
      B. aUniqueName is the unique name you gave your SfListView in your XAML

      <Button Command="{Binding Path=BindingContext.ItemSelectedCommand, Source={x:Reference aUniqueName}}" />

    This should map your Button to the same source that is used by your SfListView.

Sign In or Register to comment.