Search code examples
c#wpfxamlwindows-phone-8longlistselector

Create a longlist in windows phone 8 with textboxes


I am working on a windows phone 8 app.

In one of its screen the user will see a list of items he wants to purchase. He can select the items he want to purchase and specify the quantity for each item.

As per my understanding, longlist selector can be used for this scenario.

Currently, I am able to display the list to the user but the problem I am facing is that I am not able to retrieve the quantity specified by the user for each item from the respective textboxes.

please guide me how can i retrieve those values from the respective textboxes.

============= XAML SOURCE CODE FOR THE SAME =================

<phone:PhoneApplicationPage.Resources>
    <DataTemplate x:Key="OrderItemListTemplate">
        <Grid>
            <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding ItemName}" VerticalAlignment="Center"/>
            <TextBox LostFocus="vQtyLostFocus" GotFocus="vQtyGotFocus"   HorizontalAlignment="Right" VerticalAlignment="Top" Height="72" TextWrapping="Wrap" Text="" Width="100" InputScope="Number"/>
        </Grid>
    </DataTemplate>
</phone:PhoneApplicationPage.Resources>

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <Grid x:Name="ContentPanel" Grid.Row="2" Margin="12,0,12,0">                
        <phone:LongListSelector x:Name="ItemList"
          Background="Transparent"
          ItemTemplate="{StaticResource OrderItemListTemplate}"
          LayoutMode="List"
          IsGroupingEnabled="true"
          HideEmptyGroups ="true" SelectionChanged="Item_SelectionChanged"/>
    </Grid>        
</Grid>

Solution

  • Refer to the below link. Replace the check box with textbox and you can retrieve values of your textboxes by their name.

    Loop through longlistselector to get checkbox in itemtemplate