Method being passed entire list instead of specific element

BigSlug 21 Reputation points
2022-09-07T17:22:06.027+00:00

Firstly I apologise; my knowledge of xamarin and c# is non-existent therefore I'm going to butcher the terminology here.

My view "OrderReturnView.xaml" looks like this;

238725-image.png

The plus (+) button for each line is defined as per;

OrderReturnView.xaml;

<!-- PLUS BUTTON -->  
<Button   
    Grid.Row="0" Grid.Column="6"   
    IsVisible="{Binding IsPlusButtonEnabled}"  
    IsEnabled="{Binding IsActionable}"  
    Style="{StaticResource PlusMinusButton}" Text="+"   
    Command="{Binding Path=BindingContext.PlusCommand, Source={x:Reference Name=ThisPage}}"  
    CommandParameter="{Binding .}"/>  

ReturnViewModel.cs;
238716-image.png

Upon clicking "+" the "obj" passed to the command is the specific line that had the "+" clicked;
238680-image.png

I added "ShowReturnReasonCodeDialog" to the plus command - this just sets the "IsVisible" bound bools to "true" to display the reason code selection popup. The user then selects a reason code from a drop down and clicks confirm.

Excerpt of the popup definitions, specifically the "confirm" button which is what I'm having problems with;

OrderReturnView.xaml (added a template with visibility controlled via a bool value);

<!-- RETURN REASON CODE SELECTION POPUP GRID -->  
<templates:ReturnReasonCodeDialog   
    Grid.Column="0"  
    Grid.Row="0"  
    Grid.ColumnSpan="3"  
    Grid.RowSpan="7"  
    IsVisible="{Binding ReturnReasonCodePopupVisibility}" />  

ReturnReasonCodeDialog.xaml template the popup's "confirm" button definition;

<ContentView xmlns="http://xamarin.com/schemas/2014/forms"   
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
             xmlns:i18n="clr-namespace:Xfulfilment.Helpers;assembly=Xfulfilment"  
             x:Class="Xfulfilment.Templates.ReturnReasonCodeDialog"  
             x:Name="ThisPage">  
...  
	<Button IsEnabled="{Binding IsActionable}"  
			Style="{StaticResource AcceptButton}"  
			Text="{i18n:Translate confirm_button}"  
			Padding="0,0,0,0"  
			Margin="5,0,10,0"  
			VerticalOptions="Center"  
			HorizontalOptions="Start"   
			Command="{Binding Path=BindingContext.ConfirmReasonCodePopupCommand, Source={x:Reference Name=ThisPage}}"  
			CommandParameter="{Binding .}"/>  

ViewModel;

238752-image.png

The issue here is that when "confirm" is clicked the data passed to "obj" is the entire collection of lines;
238689-image.png

Whereas I just want the line that had the "+" clicked on it just before the popup was shown. I am guessing the problem here is something to do my Command/CommandParameter definitions for the confirm button however having had a read up on them I'm still unsure what I need to do - any ideas?

Developer technologies | .NET | Xamarin
{count} votes

Answer accepted by question author
  1. Michael Taylor 61,106 Reputation points
    2022-09-08T15:48:40.093+00:00

    Ok so you are using a list view but you aren't actually selecting the item in the list. In that case selection isn't going to work as you aren't using it. At this point I think you have a couple of options. Before calling ShowReturnReasonCodeDialog set the view model's SelectedLine property to the line item.

       if (String.IsNullOrWhiteSpace(returnDetailLine.ReasonCode))  
       {  
          SelectedLine = returnDetailLine;  
          ShowReturnReasonCodeDialog();  
       }  
    

    The alternative would be to pass the returnDetailLine to ShowReturnReasonCodeDialog and have it do something similar.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.