Click here to Skip to main content
15,880,364 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,
I have created a **ListView** which displays one table.
And I have created 2 data templates which has one text box and button.
What I want is when user enters any value in textbox it should be passed as **command parameter** to the button
When I pass parameter as

C#
CommandParameter="{Binding ElementName=txtQuantity}"


It gives me null in the parameter.

Here's the full code snippet
C#
<ListView
            Margin="5,9,11,128"
            Name="listViewMedicineInfo"
            Grid.ColumnSpan="2"
            Grid.Row="1"
            Grid.Column="0"

            MinWidth="250" MinHeight="100"

            ItemsSource="{Binding ShowMedicineDetail}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Loaded">
                    <i:InvokeCommandAction  Command="{Binding Path=ReturnMedicineInfoCommand}">
                    </i:InvokeCommandAction>
                </i:EventTrigger>

            </i:Interaction.Triggers>
            <ListView.View>
                <GridView>

                    <GridViewColumn   Header="Item Name" DisplayMemberBinding="{Binding Path=ItemName}" ></GridViewColumn>
                    <GridViewColumn Header="Brand Name" DisplayMemberBinding="{Binding Path=BrandName}"></GridViewColumn>
                    <GridViewColumn Header="Price" DisplayMemberBinding="{Binding Path=Price}"></GridViewColumn>
                    <GridViewColumn Header="In Stock" DisplayMemberBinding="{Binding Path=Quantity}"></GridViewColumn>
                    <GridViewColumn Header="Expiry Date" DisplayMemberBinding="{Binding Path=ExpiryDate}"></GridViewColumn>
                    <GridViewColumn Header="Quantity">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate x:Name="dtTemplate">
                                <TextBox  Width="50" Text="{Binding TextBoxValue,Source={StaticResource medicinedetails}, UpdateSourceTrigger=PropertyChanged}" ></TextBox>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>

                    </GridViewColumn>
                    <GridViewColumn>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Button Content="Update"
                                        Command="{Binding Path=DataContext.ReturnSelectedMedicineCommand,RelativeSource={RelativeSource AncestorType={x:Type ListView}}}"
                                        CommandParameter="{Binding ElementName=txtQuantity}">
                                </Button>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>





Thanks for the help...
Cheers!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900