2015-05-27 74 views
2

大家好,我在Windows Phone應用程序的工作,我奮力訪問內部列表元素時用戶會點擊在列表框中的特定項目我得到的輸出喜歡這個使用linq查找列表中的值?

enter image description here

例如:假設用戶將點擊[0]索引項目i想要得到[0] 1,1 480,[2] 749,[3] 270,並且當用戶將點擊1索引項目i希望得到這樣的[0] 1值,1 810, [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類和我在這裏面臨的問題訪問分組項目如何訪問分組項目時用戶會點擊一個項目上的列表框

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) 
     { 

     } 


    } 

和列表抽頭可變

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; } 
    } 

顯示數據

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


    } 
+6

你嘗試過什麼?除非你證明你自己已經做出了一些努力來解決這個問題,否則你不會在這裏得到很好的答案。 –

+0

您好Peter Lillevold先生我想根據外部列表索引 – user

+1

訪問內部列表項目。問題是:顯示您的嘗試;什麼不工作。 –

回答

0

您不應該使用LongListSelector的Tap事件,而應該使用use a DataTemplate和其中。事情是這樣的:

<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> 

注意TapImage

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

這裏是如何得到事件的DataContext

private void GetName_Tap(object sender, System.Windows.Input.GestureEventArgs e) 
{ 
    var element = (FrameworkElement)sender; 
    StaffData data = (StaffData)element.DataContext; 
    MessageBox.Show(data.Name); 
}