2017-08-31 17 views
0

私はlistViewと項目を選択したイベントがあります。リストの表示時に最初の項目をデフォルトで選択したいと考えています。最初のアイテムを作るために自分のコードに必要な変更がされているリストビューのデフォルトを選択するにはどうデフォルトリストビューの最初の項目の選択

listView.ItemSelected += (sender, e) => 
     { 
      var data = ((ListView)sender).SelectedItem as StaticListDetails; 
      Detail = data.page;    
     }; 

 ListView listView = new ListView 
     { 
      ItemsSource = staticSpListDetailses, 

      ItemTemplate = new DataTemplate(() => 
      { 

       var nameLabel = new Label(); 
       nameLabel.FontSize = 18; 
       nameLabel.WidthRequest = 180; 
       nameLabel.HorizontalTextAlignment = TextAlignment.Start; 
       nameLabel.FontAttributes = FontAttributes.Bold; 
       nameLabel.SetBinding(Label.TextProperty, "Name"); 

       var subtitlelabel = new Label(); 
       subtitlelabel.FontSize = 16; 
       subtitlelabel.HorizontalTextAlignment = TextAlignment.Start; 
       subtitlelabel.TextColor = Color.Silver; 
       subtitlelabel.SetBinding(Label.TextProperty, "SubTitle"); 

       var arrowmarklabel = new Label(); 
       arrowmarklabel.FontSize = 20; 
       arrowmarklabel.HorizontalOptions = LayoutOptions.EndAndExpand; 
       arrowmarklabel.VerticalOptions = LayoutOptions.Center; 
       arrowmarklabel.TextColor = Color.Black; 
       arrowmarklabel.Text = ">"; 
       arrowmarklabel.FontAttributes = FontAttributes.Bold; 

       var arrowmarklabel1 = new Label(); 
       arrowmarklabel1.WidthRequest = 90; 

       var insideStackLayout = new StackLayout 
       { 
        Orientation = StackOrientation.Vertical, 
        VerticalOptions = LayoutOptions.Center, 
        Spacing = 5, 
        Children = 
        { 
         nameLabel,subtitlelabel 
        } 
       }; 

       var image = new Image(); 
       image.Scale = 0.8; 
       image.SetBinding(Image.SourceProperty, "ImageSourceUrl"); 

       return new ViewCell 
       { 
        View = new StackLayout 
        { 
         Padding = new Thickness(10,0, 5, 0), 
         Orientation = StackOrientation.Horizontal, 
         Children = { 

          new StackLayout { 
           VerticalOptions = LayoutOptions.Center, 
           Orientation=StackOrientation.Horizontal, 

           Children = { 
            image,insideStackLayout,arrowmarklabel 
           } 
          } 
         } 
        } 
       }; 
      }) 
     }; 

は、ここで私のItemselectedイベントです。

答えて

0
listView.SelectedItem = staticSpListDetailses?.FirstOrDefault() 
関連する問題