Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

ListView navigation to other view.

$
0
0

I have created listview in code behind and i need to navigate to the other view when items in listview is clicked.

Here is my code:

public class StaticListDetails
    {
        public string Name { get; set; }
        public string ImageSourceUrl { get; set; }
        public Page page { get; set; }

   }

ObservableCollection<StaticListDetails> staticSpListDetailses = new ObservableCollection<StaticListDetails>();
    public ItemsDetailsView()
    {
        staticSpListDetailses.Add(new StaticListDetails { Name = "Images", ImageSourceUrl = "next.png", page = new ImagesView() });
        staticSpListDetailses.Add(new StaticListDetails { Name = "Flowers", ImageSourceUrl = "next.png",page = new FlowersView() });

ListView listView = new ListView
        {
            ItemsSource = staticSpListDetailses,

           ItemTemplate = new DataTemplate(() =>
            {

               Label nameLabel = new Label();
                nameLabel.FontSize = 20;
                nameLabel.HorizontalTextAlignment = TextAlignment.Center;
                nameLabel.SetBinding(Label.TextProperty, "Name");

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

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

                           new StackLayout {
                                VerticalOptions = LayoutOptions.Center,
                                Orientation=StackOrientation.Horizontal,
                                Spacing = 5,
                                Children = {
                                    image,nameLabel
                                }
                            }
                        }
                    }
                };
            })
        };

       listView.RowHeight = 60;
        DynamicListView.RowHeight = 60;

        listView.ItemSelected += (sender, e) =>
        {
            Navigation.PushAsync(((StaticListDetails)sender).SelectedItem).page);
        };

so,here iam getting error that no definition for selectedItem.
how i have to define SelectedItem in order to navigate for other view.


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>