从MainPage调用Listview

时间:2017-10-18 03:17:41

标签: c# xamarin mobile

我正在尝试从主页调用我的ListView。包含列表中项目描述的数据位于名为datamodel的类中。部署应用程序时,我无法查看列表。应用程序未部署。我真的不确定从什么角度开始,我将从Xamarin Forms书中的示例创建一个可滚动的列表,其中包含列表中每行的文本和详细信息。

    public MainPage()
    {

        Picker picker = new Picker
        {
            Title = "Movies",

            VerticalOptions = LayoutOptions.CenterAndExpand
        };
        //

        DataModel thisList = new DataModel();
        ListView myListView = thisList.ListViewGrouped();

        var options = new List<string> {
            "Kill Bill", "Matrix", "Zombieland", "The Dark Knight", "Terminator", "Apocalypse Now", "Resouvoir dogs", "Horrible Bosses", "The Breakup", "Wedding Crashers", };
        picker.SelectedIndexChanged += (sender, e) =>
        {
            pickmovie = picker.Items[picker.SelectedIndex];

        };
        foreach (string optionName in options) picker.Items.Add(optionName);
        //listView.ItemTapped += async (sender, e) => { await DisplayAlert("Tapped", e.Item.ToString() + " was selected.", "OK"); ((ListView)sender).SelectedItem = null; };
        //this.Content = listView;

        Label valuelabel = new Label
        {
            Text = "0",
            FontAttributes = FontAttributes.Bold,
            FontSize = 30,
            HorizontalOptions = LayoutOptions.Center
        };

        Stepper stepper = new Stepper
        {
            Minimum = 0,
            Maximum = 10,
            Increment = 1,
            HorizontalOptions = LayoutOptions.Center,
            VerticalOptions = LayoutOptions.CenterAndExpand

        };


        stepper.ValueChanged += (sender, e)=>
        {
            valuelabel.Text = String.Format(" {0:F1}", e.NewValue);
            movieamount = stepper.Value.ToString();

        };



        Picker payment = new Picker
        {
            Title = "Payment Method",
            VerticalOptions = LayoutOptions.CenterAndExpand

        };
         var options1 = new List<string> {"Visa", "MasterCard", "AmericanExpress", "Free",};

         foreach (string optionName in options1) payment.Items.Add(optionName);
        payment.SelectedIndexChanged += (sender, e) =>
        {
            paymentSelected = payment.Items[payment.SelectedIndex];
        };

        //TimePicker was here



        Label totalLabel = new Label

        {

            HorizontalOptions = LayoutOptions.CenterAndExpand,
            FontSize = 40,
            FontAttributes = FontAttributes.Bold | FontAttributes.Italic


        };

        DatePicker datePicker = new DatePicker
        {
            Format = "D",
            VerticalOptions = LayoutOptions.CenterAndExpand,

        };

        //---Handle Inline---

        datePicker.DateSelected += (object sender, DateChangedEventArgs e) =>
        {
            //eventValue.Text = e.NewDate.ToString();
            dateSelected = e.NewDate.ToString();

        };

        TimePicker timePicker = new TimePicker

        {
            Format = "T",
            VerticalOptions = LayoutOptions.CenterAndExpand

        };
        // set inline handler

        timePicker.PropertyChanged += (sender, e) =>
        {
            if (e.PropertyName == TimePicker.TimeProperty.PropertyName)

            {
                timeSelected = timePicker.Time.ToString();
            };

        };

        Button button = new Button

        {
              Text = "Submit",

              FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Button)),
              HorizontalOptions = LayoutOptions.CenterAndExpand,
              VerticalOptions = LayoutOptions.Fill

        };

        button.Clicked += (sender, args) =>
        {
          totalLabel.Text = "You have ordered " + movieamount  + " " +
          pickmovie + " \n You will be paying with " + paymentSelected + " " +
          "Your delivery will be delivered at " + dateSelected + " " +  timeSelected;


        }; 





        StackLayout stackLayout = new StackLayout
        {
            Children =

            {
                myListView,
                picker,
                payment,
                valuelabel,
                stepper,
                datePicker,
                totalLabel,
                timePicker,
                button,


            }

        };
        BackgroundColor = Color.Yellow;
        this.Content = stackLayout;
    }
}

}

0 个答案:

没有答案