0
votes

Inside List Item button ActionText not showing after adding BindingContext on Button. after removing the BindingContext from Button then ActionText showing,but on button click event not working.

<ListView x:Name="ShipmentData" 
    HasUnevenRows="True" ItemsSource="{Binding ShipmentData}" SelectedItem="{Binding SelectedShippedItem}"
    BackgroundColor="White">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Grid Margin="0" Padding="5" x:Name="Item">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Label Text="{Binding ShipTransId}" Grid.Row="0" IsVisible="False"/>
                        <Label Text="{Binding LabelUri}" Grid.Row="0" IsVisible="False"/>
                        <Label Text="{Binding OrderNumber}" Grid.Row="0" Grid.Column="0" HorizontalTextAlignment="Center"/>
                        <Label Text="{Binding ShippingId}" Grid.Row="0" Grid.Column="1" HorizontalTextAlignment="Center"/>
                        <Label Text="{Binding Status}" Grid.Row="0" Grid.Column="2" 
                               HorizontalTextAlignment="Center" HorizontalOptions="Center" VerticalOptions="Center"/>
                        <Button Text="{Binding ShipmentData.ActionText}" VerticalOptions="Center" 
                        HorizontalOptions="Center" BorderRadius="10"
                        Command="{Binding PrintLabel}" Grid.Row="0" Grid.Column="3" Margin="5,0,0,0"
                        BindingContext="{Binding Source={x:Reference ShipmentData}, Path=BindingContext}"
                        CommandParameter="{Binding Source={x:Reference Item}, Path=BindingContext}"/>
                    </Grid>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
        <ListView.Behaviors>
             <eventToCommand:EventToCommandBehavior EventName="ItemTapped" Command="ShippedItemTapped"/>
        </ListView.Behaviors>
</ListView>

Here is my PageModel

public ObservableCollection<ShowShipmentData> ShipmentData
{
    get { return _shipmentData; }
    set
    {
        _shipmentData = value;
        RaisePropertyChanged();
    }
}

ShipmentData = DependencyService.Get<ISQLite2().ShowShipmentTableData(GlobalVariable.BranchId); 

public Command PrintLabel
{
    get
    {
        return new Command(async (e) =>
        {
            ShowShipmentData selecedItem = (e as ShowShipmentData);
        });
    }
}

How to solve this?

1
We need your relevant code in page model also.Woj
Hello I Edited my qus,Please see this.Vidhya
DependencyService.Get<ISQLite2().ShowShipmentTableData(GlobalVariable.BranchId); Is that method returning a string?Woj
Is the ActionText a property of ShowShipmentData? Then it should just be: <Button Text="{Binding ActionText}"Gerald Versluis
ActionText is a Property of ShowShipmentTableData Class and DependencyService.Get<ISQLite2().ShowShipmentTableData(GlobalVariable.BranchId); returning a list that are bind to the listviewVidhya

1 Answers

0
votes

try modifying your Xaml code as below,

remove the below items

Command="{Binding PrintLabel}" BindingContext="{Binding Source={x:Reference ShipmentData}, Path=BindingContext}" CommandParameter="{Binding Source={x:Reference Item}, Path=BindingContext}"

and update with the below code, give your page a name and mention in the 'Command'

 Command="{Binding Source={x:Reference yourPageName}, Path=BindingContext.PrintLabel}"
                                                        CommandParameter="{Binding .}"

in the code behind, change your PrintLabel command property similar to below,

Command printLabel;
    public Command PrintLabel
    {
        get
        {
            return printLabel ?? (printLabel = new Command<ShowShipmentData>(ExecuteSelected));
        }
    }

    private void ExecuteSelected(ShowShipmentData selectedItem)
    {

    }