2012-12-16 4 views
1

그래서 곧 개체 목록에 바인딩 될 LongListSelector가 있습니다. LongListSelectorItems 중 하나가 내가 특정 객체가 탭 얻고, 내가 객체WP8의 LongListSelector 항목에서 데이터를 가져 오는 방법

private void PeopleList_Tap_1(object sender, System.Windows.Input.GestureEventArgs e) 
    { 
     MessageBox.Show("SUCCESS"); 
    } 

에 대한 전체 정보를 표시 할 수 있도록 다른 화면으로 그 개체를 전달할 수있는 능력을 가지고 있음을 탭하면 내가 원하는 무엇

입니다 내 수돗물이 작동 중입니다. 선택한 객체를 가져 오는 방법이나 NavigationService를 사용하여 다른 페이지로 전달하는 방법을 알 수 없습니다.

답변

2

이벤트 및 LongListSelector.SelectedItem 속성을 사용하면 선택한 항목을 가져올 수 있습니다.

+0

고마워요! 나는 이것을 시험해 볼 것이다! 이 개체를 다른 페이지로 전달하려면 어떻게해야합니까? – dspiegs

+0

@ bam2403이를 수행하는 한 가지 방법은 Tap 또는 SelectionChanged 이벤트가 발생하면 채울 수있는 선택한 개체에 대한 전역 변수를 갖는 것입니다. 그런 다음 다음 페이지로 이동하면 해당 전역 변수에 액세스 할 수 있습니다. – joelc

3

아래는 최신 앱에서 곧바로 가져옵니다.

개체를 직접 전달할 수는 없지만 텍스트 데이터는 전달할 수 있습니다. 내 경우에, ID : 수신 측에 다음

private void WishListBoxSelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
    if (WishListBox != null && WishListBox.SelectedItem != null) 
    { 
     var selectedItem = (Models.Gift)WishListBox.SelectedItem; 
     WishListBox.SelectedIndex = -1; 
     var id = selectedItem.Id; 
     NavigationService.Navigate(new Uri("/Views/Gift/GiftView.xaml?action=load&id=" + id, UriKind.Relative)); 
    } 
} 

: 내 경우

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) 
{ 
    base.OnNavigatedTo(e); 
    if (NavigationContext.QueryString.ContainsKey("action")) 
    { 
     if (NavigationContext.QueryString["action"]=="load") 
     { 
      PageTitle.Text = "edit gift"; 
      giftVm.Gift = App._context.Gifts.Single(g => g.Id == Int32.Parse(NavigationContext.QueryString["id"]));      
     } 
     else if (NavigationContext.QueryString["action"] == "new") 
     { 
      PageTitle.Text = "new gift"; 
     } 
     else if (NavigationContext.QueryString["action"] == "newWishList") 
     { 
      App.vm = ((MainViewModel)App.vm).Me; 
     } 
    } 
    else 
    { 
     MessageBox.Show("NavigationContext.QueryString.ContainsKey('action') is false"); 
    } 
} 

는, 데이터는 DB에 저장된다. 선택한 항목을 올바른 개체 유형으로 캐스팅 한 다음 ID를 확인하고 조회를 수행하는 다음 페이지로 전달합니다.

이 정보가 도움이되기를 바랍니다.

+0

웹 API에서 데이터를 가져 오는 경우 어떻게해야합니까? 코드를 어떻게 변경해야합니까? –

+0

줄 : giftVm.Gift = App._context.Gifts.Single (g => g.Id == Int32.Parse (NavigationContext.QueryString [ "id"]))); 은 데이터베이스에서 레코드를 조회하여 내 ViewModel에 할당합니다. 이 줄을 변경하여 API를 호출하고 응답을 처리 할 수 ​​있습니다. –

관련 문제