2

Hi all I am working on windows phone app and i am struggling to access the inner list element when user will Tap a particular item in listbox i am getting the output like this

enter image description here

for example: suppose user will tap [0]index item i want to get [0]1,1480,[2]749,[3]270 and when user will tap 1index item i want get value like [0]1,1810,[2]1080,[3]271

UI

 <phone:LongListSelector Name="list_professions"  
                         LayoutMode="List"   
                         Tap="list_professions_Tap" 
                         Padding="5,15,5,15" 
                         IsGroupingEnabled="True">
  </phone:LongListSelector>

Json Class and Variable

   private class RootObject
    {
        public string flag { get; set; }
        public string message { get; set; }
        public Result result { get; set; }
    }
    private class Result
    {
        public List<List<string>> Professions { get; set; }
    }

showing data on Listbox

  void onResponse(object sender, DownloadStringCompletedEventArgs e)
    {
        try
        {
            onLoadingStope(sender, e);
            var rootObject = JsonConvert.DeserializeObject<RootObject>(e.Result);

            string flag = rootObject.flag;
            string msg = rootObject.message;
            if (flag.Equals("1"))
            {

                foreach (var temp in rootObject.result.Professions[0])
                {

                    profess.Add(new Result() { Professions = rootObject.result.Professions });
                    var flattenProfessions = rootObject.result.Professions.SelectMany(x => x).ToList();
                    list_professions.ItemsSource = rootObject.result.Professions;

                }
            }
            else
            {
                Console.WriteLine("Error message - " + msg);
                MessageBox.Show("Oops! response : " + msg);
            }
        }
        catch(Exception ex)
        {

        }


    }

and List Tap Here i am facing problem to access grouped item how to access grouped item when user will tap a item

   private void list_professions_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {


    }
Eldho
  • 7,795
  • 5
  • 40
  • 77
user
  • 125
  • 8
  • 6
    What have you tried? Unless you show that you have done some effort to solve this yourself, you won't get very good answers here on SO. – Peter Lillevold May 27 '15 at 08:50
  • Hello Peter Lillevold sir i want to access inner list item based on outer list index – user May 27 '15 at 09:05
  • 1
    The question was: show your attempt; and what is not working. – L-Four May 27 '15 at 09:14
  • Sir L-Three i am not able to get all the inner list item when user will Tap a particular item – user May 27 '15 at 09:17
  • Provide us a sample code of how you think it is, we'll then help you along – Schuere May 27 '15 at 09:19
  • @user If you are binding the LongListSelector with a model , on your tap event, you get selected item, you can cast into your model and get the inner elements . Or else filter the Item Source with the key that user tapped. I assume u have unique key – Eldho May 27 '15 at 10:38
  • Sir Eldho i dont have any unique key i have only group of items and i am not following MVVM model – user May 27 '15 at 10:41
  • you will be grouping the items with a unique group , can't you do a filter on the source with the same , the selected group MAY get in the Tapped item. Please provide the code where you set the itemsource for the list and specify your model. – Eldho May 27 '15 at 10:52
  • Your tap event should only send one item as a default behaviour`private void Item_tap(object sender, RoutedEventArgs e) { var element = (FrameworkElement)sender; }` go through this [longlistselector_tap](http://stackoverflow.com/questions/14215227/longlistselector-item-tap) – Eldho May 27 '15 at 11:19
  • Eldho sir thanks but sir when i will tap a item i will get that item index and also get inner list all item through main index.. – user May 27 '15 at 11:27
  • This is basically [your question from yesterday](http://stackoverflow.com/questions/30455169/how-to-access-inner-list-item-in-c-sharp) with some additional details, but you still fail to provide the necessary details. What do you want to do -- FYI "i want to access inner list item based on outer list index" is NOT a good answer to that question. – BCdotWEB May 27 '15 at 11:33

1 Answers1

0

You shouldn't use the Tap event of the LongListSelector, but instead use a DataTemplate and use the Tap event of the elements therein. Something like this:

<phone:PhoneApplicationPage.Resources>
    <DataTemplate x:Key="TileDataTemplate">
        <Grid Background="{StaticResource TransparentBrush}"
              Margin="0, 0, 0, 12" Height="60">
            <TextBlock Text="{Binding Name}" Margin="60, 10, 0, 0" FontSize="24" Height="60">
            </TextBlock>
            <Image x:Name="GetName" Tap="GetName_Tap" Grid.Column="0" Source="/Assets/AppBar/Delete.png" Height="40" Width="40"
                            Margin="0, 6, 0, 5" HorizontalAlignment="Right" VerticalAlignment="Top" />
        </Grid>
    </DataTemplate>
</phone:PhoneApplicationPage.Resources>

Note the Tap on the Image.

<phone:LongListSelector
                    SelectionChanged="MainLongListSelector_SelectionChanged"
                    Margin="10,6,0,0"
                    ItemsSource="{Binding Staff.Items}"
                    LayoutMode="Grid"
                    GridCellSize="400,80"
                    ItemTemplate="{StaticResource TileDataTemplate}"
                    />

Here's how to get the DataContext of the event:

private void GetName_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
   var element = (FrameworkElement)sender;
   StaffData data = (StaffData)element.DataContext;
   MessageBox.Show(data.Name);
}
Community
  • 1
  • 1
BCdotWEB
  • 1,009
  • 1
  • 14
  • 35