2016-07-15 2 views
0

목록에있는 데이터와 전자 메일을 표시하려고합니다. 나는 부통령에게해야하고 외부 전자 우편 플래트 홈에 열기 위하여 나는 그들의 전자 우편의 열려있는 연결을 각각 원하는다. 그러나 코드가 제대로 작동하지 않는 것으로 보입니다. 부통령에게 전자 메일이 하나만 열리 며 그 내용을 담고있는 레이블 전체가 이에 반응하는 것처럼 보입니다.목록에있는 데이터 표시 Xamarin.Forms

이것은 스크린 샷입니다. 여러 부회장를 들어, 당신은 단지 하나 개의 레이블에 텍스트를 추가하고 있기 때문에

enter image description here

내 Xmal 코드

<Label Text="Vice-President:" FontSize="18" FontAttributes="Bold" XAlign="Center" TextColor="Black"/> 
       <StackLayout x:Name="vpDetails"> 

       </StackLayout> 

내 C# 코드는

foreach (var item in leaderDetail) 
     { 
      Boolean IsPresident = item.IsPresident; 

      if (IsPresident == true) 
      { 
       lbPresidentName.Text = item.Name; 
       btnPresidentEmail.Text = item.Email; 

       var tgrPresident = new TapGestureRecognizer(); 
       tgrPresident.Tapped += (s, e) => Device.OpenUri(new Uri("mailto:" + item.Email)); 
       btnPresidentEmail.GestureRecognizers.Add(tgrPresident); 
      } 
      else 
      { 
       vpDetails.Children.Add(new Label { Text = item.Name ,FontSize=14, HorizontalOptions = LayoutOptions.Center}); 

       vpDetails.Children.Add(new Label { Text = item.Email, FontSize=14, HorizontalOptions = LayoutOptions.Center, x:name="lbvPresident1Email"}); 

       //lbvPresident1Name.Text = item.Name; 
       //lbvPresident1Email.Text = item.Email; 

       var tgrVPEmail = new TapGestureRecognizer(); 
       tgrVPEmail.Tapped += (s, e) => Device.OpenUri(new Uri("mailto:" + item.Email)); 
       lbvPresident1Email.GestureRecognizers.Add(tgrVPEmail); 
      } 

     } 

답변

0

이 문제를 해결하려면 StackLayout을 컨테이너로 사용해야합니다. Label의 var를 만들고 foreach 루프에 추가합니다.

DetailedClub.xaml

<StackLayout x:Name="vpDetails"></StackLayout> 

DetailedClub.xaml.cs

foreach (var item in leaderDetail) 
{ 
    //Create a new label for the Email 
    var VpEmail = new Label { Text = item.Email, FontSize = 14, HorizontalOptions = LayoutOptions.Center }; 

    vpDetails.Children.Add(new Label { Text = item.Name ,FontSize=14, HorizontalOptions = LayoutOptions.Center}); 

    vpDetails.Children.Add(VpEmail); 

    var tgrVPEmail = new TapGestureRecognizer(); 
    tgrVPEmail.Tapped += (s, e) => Device.OpenUri(new Uri("mailto:" + item.Email)); 
    VpEmail.GestureRecognizers.Add(tgrVPEmail); 
} 
1

이다. 즉, 부통령 1 명과 제스처 인식기를 전자 메일에 추가하고 텍스트를 추가하여 다른 제스처 인식기를 등록해야합니다. 그런 다음 탭 제스처가 첫 번째 것으로 인식됩니다.

기본적으로 전체 코드가 실행 된 후에는 lbvPresident1Name 레이블에 부사 (副) 이름과 전자 메일이 모두 포함되어 있으며 여러 개의 GestureRecognizers (부전승장마다 하나씩)가 있습니다.

이 문제를 극복하려면 부회장 목록을 만들고 각 부통령을 품목으로 추가하거나 컨테이너를 추가하고 각자의 라벨을 즉시 작성해야합니다. https://developer.xamarin.com/samples/xamarin-forms/WorkingWithListview/

StackLayout 구성 요소는 시나리오에서 최선의 선택이 될 것입니다, 당신은 코드에서 즉시 항목을 추가 할 수있는 컨테이너를 만들려면 - Xamarin.Forms은 설명서를 참조하십시오에

는 목록보기 만듭니다. 현재 레이블 대신 StackLayout을 넣은 다음 foreach 루프에 레이블을 만들고 Children.Add 메서드를 사용하여 StackLayout에 넣습니다.

관련 문제