当前位置: 首页>>代码示例>>C#>>正文


C# ListView.SetBinding方法代码示例

本文整理汇总了C#中ListView.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# ListView.SetBinding方法的具体用法?C# ListView.SetBinding怎么用?C# ListView.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ListView的用法示例。


在下文中一共展示了ListView.SetBinding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToDoListPage

        public ToDoListPage()
        {
            BindingContext = new ToDoListViewModel();

            var listView = new ListView();
            listView.ItemTemplate = new DataTemplate(typeof(TextCell));

            // Bindings para los items de la lista
            listView.SetBinding(ListView.ItemsSourceProperty, "ToDoItems");
            listView.SetBinding(ListView.SelectedItemProperty, "SelectedToDoItem");

            // Bindings para definir la información que se muestra por cada fila
            listView.ItemTemplate.SetBinding(TextCell.TextProperty, "Name");
            listView.ItemTemplate.SetBinding(TextCell.DetailProperty, "Description");

            var saveButton = new ToolbarItem { Text = "Save" };

            var addButton = new ToolbarItem { Text = "Add" };

            Content = new StackLayout {
                Children = {
                    listView
                }
            };

            ToolbarItems.Add(saveButton);
            ToolbarItems.Add(addButton);
        }
开发者ID:fferegrino,项目名称:mvvm,代码行数:28,代码来源:ToDoListPage.cs

示例2: Main2Page

        public Main2Page()
        {
            Button goButton;
            Entry searchEntry;
            StackLayout mainLayout;
            Title = "Movies Sample";

            Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);

            var searchLayout = new StackLayout
            {
                Spacing = 10,
                Orientation = StackOrientation.Horizontal,
            };

            searchLayout.Children.Add(searchEntry = new Entry
            {
                Placeholder = "Movie Name",
                HorizontalOptions = LayoutOptions.FillAndExpand
            });
            searchLayout.Children.Add(goButton = new Button
            {
                Text = "Search", IsEnabled = true,
                HorizontalOptions = LayoutOptions.End
            });

            Content = mainLayout = new StackLayout
            {
                Padding = new Thickness(10),
                Spacing = 10,
                Orientation = StackOrientation.Vertical,
            };

            
            mainLayout.Children.Add(searchLayout);
            
            var movieListView = new ListView
            {
                ItemTemplate = new DataTemplate(typeof(ImageCell))
            };

            mainLayout.Children.Add(movieListView);
            
            searchEntry.SetBinding(Entry.TextProperty, new Binding("SearchString"));
            goButton.SetBinding(Button.CommandProperty, new Binding("GetMoviesCommand"));
            movieListView.SetBinding(ListView.ItemsSourceProperty, new Binding("Movies"));
            movieListView.SetBinding(ListView.SelectedItemProperty, new Binding("SelectedMovie"));
            movieListView.ItemTemplate.SetBinding(ImageCell.TextProperty, new Binding("Title"));
            movieListView.ItemTemplate.SetBinding(ImageCell.ImageSourceProperty, new Binding("PosterUrl"));
            movieListView.ItemTemplate.SetBinding(ImageCell.DetailProperty, new Binding("Score"));
             
        }
开发者ID:Milton761,项目名称:EduticNow,代码行数:52,代码来源:Main2Page.cs

示例3: AgendaDayView

        public AgendaDayView ()
        {
            SetBinding (AgendaDayView.NavigationProperty, new Binding ("Navigation"));

            var listView = new ListView {
                ItemTemplate = new DataTemplate(typeof(AgendaCell)),
                RowHeight = 96
            };

            listView.SetBinding (ListView.ItemsSourceProperty, "Slots");
            listView.SetBinding (ListView.SelectedItemProperty, "SelectedSlot");

            Content = listView;
        }
开发者ID:vgvassilev,项目名称:couchbase-connect-14,代码行数:14,代码来源:AgendaDayView.cs

示例4: MainPage

		public MainPage ()
		{
			Title = "TripLog";

			var itemTemplate = new DataTemplate (typeof(TextCell));
			itemTemplate.SetBinding (TextCell.TextProperty, "Title");
			itemTemplate.SetBinding (TextCell.DetailProperty, "Notes");

			var entries = new ListView {
				ItemTemplate = itemTemplate
			};
			entries.SetBinding (ListView.ItemsSourceProperty, "LogEntries");
			entries.SetBinding (ListView.IsVisibleProperty, "IsBusy", converter: new ReverseBooleanConverter());

			entries.ItemTapped += (sender, e) => 
			{
				var item = (TripLogEntry) e.Item;
				vm.ViewCommand.Execute (item);
			};

			var newButton = new ToolbarItem { Text = "New" };
			newButton.SetBinding (ToolbarItem.CommandProperty, "NewCommand");
			ToolbarItems.Add (newButton);

			var loading = new StackLayout {
				Orientation = StackOrientation.Vertical,
				HorizontalOptions = LayoutOptions.Center,
				VerticalOptions = LayoutOptions.Center,
				Children = {
					new ActivityIndicator {
						IsRunning = true
					},
					new Label {
						Text = "Loading Entries..."
					}
				}
			};

			loading.SetBinding (StackLayout.IsVisibleProperty, "IsBusy");

			var mainLayout = new Grid {
				Children = {
					entries, 
					loading
				}
			};

			Content = mainLayout;
		}
开发者ID:blombas,项目名称:TripLog,代码行数:49,代码来源:MainPage.cs

示例5: Init

		protected override void Init ()
		{
			Title = "Test Command Binding";
			_list = new ListView () { 
				ClassId = "SampleList",
				// Note: Turning on and off row height does not effect the issue, 
				// but with row heights on there is a visual glitch with the recyclyed row spacing
				//RowHeight = SampleViewCell.RowHeight,
				HasUnevenRows = true,
				ItemTemplate = new DataTemplate (typeof(SampleViewCell)),
				BackgroundColor = Color.FromHex ("E0E0E0"),
				VerticalOptions = LayoutOptions.FillAndExpand,
				HorizontalOptions = LayoutOptions.FillAndExpand,
			};
			_list.SetBinding (ListView.ItemsSourceProperty, Binding.Create<TestListViewModel> (r => r.Items));
			_list.SetBinding (ListView.RefreshCommandProperty, Binding.Create<TestListViewModel> (r => r.RefreshCommand));
			_list.SetBinding (ListView.IsRefreshingProperty, Binding.Create<TestListViewModel> (r => r.IsRefreshing));

			var listViewModel = new TestListViewModel ();
			listViewModel.AddTestData ();
			BindingContext = listViewModel;


			_list.ItemTapped += (sender, e) =>
			{
				DisplayAlert("hello", "You tapped " + e.Item.ToString(), "OK", "Cancel");
			};

			var btnDisable = new Button () {
				Text = "Disable ListView",
			};

			btnDisable.Clicked += (object sender, EventArgs e) => {
				if (_list.IsEnabled == true){
					_list.IsEnabled = false;
					btnDisable.Text = "Enable ListView";
				}
				else {
					_list.IsEnabled = true;
					btnDisable.Text = "Disable ListView";
				}
			};

			Content = new StackLayout
			{
				VerticalOptions = LayoutOptions.FillAndExpand,
				Children = { btnDisable, _list }
			};
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:49,代码来源:Bugzilla34720.cs

示例6: ListaRespostasView

 public ListaRespostasView(List<Resposta> respostas, int respondida = 0)
 {
     try
     {
         this.BindingContext = model = new RespostaViewModel(respostas);
         
         var listViewRespostas = new ListView
         {
             SeparatorVisibility = SeparatorVisibility.None,
             BackgroundColor = Color.Transparent
         };
         listViewRespostas.ItemTemplate = respondida == 1 ? 
         new DataTemplate(typeof(ListaRespostasEnqueteRespondidaViewCell)) : 
         new DataTemplate(typeof(ListaRespostasViewCell));
         listViewRespostas.HasUnevenRows = true;
         listViewRespostas.SetBinding(ListView.ItemsSourceProperty, "Respostas");
         listViewRespostas.ItemTapped += (sender, e) =>
         {
             this.TrataClique(e.Item);
             ((ListView)sender).SelectedItem = null; 
         };
         
         var mainLayout = new StackLayout
         {
             Children = { listViewRespostas },
             HeightRequest = Acr.DeviceInfo.DeviceInfo.Hardware.ScreenHeight * 3
         };
         
         this.Content = new ScrollView{ Content = mainLayout, Orientation = ScrollOrientation.Vertical };
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
开发者ID:jbravobr,项目名称:Mais-XamForms,代码行数:35,代码来源:ListaRespostasView.cs

示例7: FootballPlayerListPage

        public FootballPlayerListPage()
        {
            this.BindingContext = new FootballPlayerViewModel ();

            Title = "Football Legends";
            var create = new ToolbarItem ();
            create.Name = "create";

            this.ToolbarItems.Add (create);
            create.Clicked += Create_Clicked;
            //	create.SetBinding (ToolbarItem.CommandProperty, "CreatePlayer");
            MyFootballList = new ListView ();
            MyFootballList.IsPullToRefreshEnabled = true;
            MyFootballList.Refreshing += MyFootballList_Refreshing;
            MyFootballList.SetBinding (ListView.ItemsSourceProperty, "Footballplayercollection");
            var cell = new DataTemplate (typeof(FootballPlayerListCell));
            MyFootballList.ItemTemplate = cell;
            MyFootballList.RowHeight = 70;

            MessagingCenter.Subscribe<FootballPlayerListCell>(this,"delete",(sender) => {
                this.BindingContext = new FootballPlayerViewModel();
                FootballPlayer dat= new FootballPlayer ();
                MyFootballList.ItemsSource = dat.GetItems ();

            },null);

            MyFootballList.ItemSelected += (object sender, SelectedItemChangedEventArgs e) =>
            {

                Navigation.PushAsync(new FootballPlayerDetailPage(e.SelectedItem));

            };

            this.Content = MyFootballList;
        }
开发者ID:CTS458641,项目名称:cts458701,代码行数:35,代码来源:FootballPlayerListPage.cs

示例8: BuildContent

        private StackLayout BuildContent()
        {
            var layout = new StackLayout ();

            _list = new ListView {
                //VerticalOptions = LayoutOptions.FillAndExpand,
                ItemTemplate = new DataTemplate(typeof(ListItemView)),
                RowHeight = 90,
            };

            _list.ItemTapped +=	(sender, e) => {
                var todoListPage = new TodoListPage ();
                Navigation.PushAsync (todoListPage);
            };

            _list.ItemSelected += (sender, e) => {
                var todoListPage = new TodoListPage ();
                Navigation.PushAsync (todoListPage);
            };

            _list.SetBinding(ListView.ItemsSourceProperty, "Data");

            layout.Children.Add (_list);
            layout.VerticalOptions = LayoutOptions.FillAndExpand;
            layout.BackgroundColor = Color.Yellow;

            return layout;
        }
开发者ID:denis121702,项目名称:BeaconBluetooth,代码行数:28,代码来源:MainPage.cs

示例9: Init

		protected override void Init ()
		{
			var listView = new ListView ();

			var selection = new Selection ();
			listView.SetBinding (ListView.ItemsSourceProperty, "Items");

			listView.ItemTemplate = new DataTemplate (() => {
				var cell = new SwitchCell ();
				cell.SetBinding (SwitchCell.TextProperty, "Name");
				cell.SetBinding (SwitchCell.OnProperty, "IsSelected", BindingMode.TwoWay);
				return cell;
			});

			var instructions = new Label {
				FontSize = 16,
				Text =
					"The label at the bottom should equal the number of switches which are in the 'on' position. Flip some of the switches. If the number at the bottom does not equal the number of 'on' switches, the test has failed."
			};

			var label = new Label { FontSize = 24 };
			label.SetBinding (Label.TextProperty, "SelectedCount");

			Content = new StackLayout {
				VerticalOptions = LayoutOptions.Fill,
				Children = {
					instructions,
					listView,
					label
				}
			};

			BindingContext = selection;
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:34,代码来源:Bugzilla31964.cs

示例10: CodedPage

		public CodedPage ()
		{
			_SomeLabel = new Label {
				XAlign = TextAlignment.Center,
			};
			_SomeLabel.SetBinding (Label.TextProperty, nameof (SomeViewModel.SomeLabel));

			var listViewItemTemplate = new DataTemplate (typeof(ImageCell));
			_ItemsListView = new ListView (ListViewCachingStrategy.RecycleElement) {
				ItemTemplate = listViewItemTemplate,
			};
			_ItemsListView.SetBinding (ListView.ItemsSourceProperty, nameof (SomeViewModel.SomeItems));
			listViewItemTemplate.SetBinding (ImageCell.TextProperty, nameof (SomeItem.ItemName));
			listViewItemTemplate.SetBinding (ImageCell.ImageSourceProperty, nameof (SomeItem.ImageUrl));
			_ItemsListView.ItemTapped += async (sender, e) => {
				var item = ((SomeItem)e.Item);
				ItemSelected (this, item);
				_ItemsListView.SelectedItem = null;
			};

			Padding = new Thickness (0, 20, 0, 0);
			Content = new StackLayout {
				VerticalOptions = LayoutOptions.Fill,
				HorizontalOptions = LayoutOptions.Fill,
				Children = {
					_SomeLabel,
					_ItemsListView,
				}
			};
		}
开发者ID:patridge,项目名称:demos-xamarin.forms-tour,代码行数:30,代码来源:CodedPage.cs

示例11: Init

        public void Init()
        {
            if (Device.OS == TargetPlatform.iOS) {
                var list = new EditableListView<Object> ();
                list.SetBinding (EditableListView<Object>.SourceProperty, "JellyBeanValues");
                list.ViewType = typeof(JellyBeanListViewCell);
                list.CellHeight = 60;
                list.AddRowCommand = new Command (() => {
                    this.DisplayAlert ("Sorry", "Not implemented yet!", "OK");
                });

                if (PageModel.JellyBeanValues != null)
                    list.Source = PageModel.JellyBeanValues;
                Content = list;
            } else {
                var list = new ListView();
                list.SetBinding (ListView.ItemsSourceProperty, "JellyBeanValues");
                var celltemp = new DataTemplate(typeof(TextCell));
                celltemp.SetBinding (TextCell.TextProperty, "Name");
                celltemp.SetBinding (TextCell.DetailProperty, "ReadableValues");
                list.ItemTemplate = celltemp;
                if (PageModel.JellyBeanValues != null)
                    list.ItemsSource = PageModel.JellyBeanValues;
                Content = list;
            }

            ToolbarItems.Add(new ToolbarItem("Add", "", () => {
                this.DisplayAlert("Sorry", "Not implemented yet!", "OK");
            }));
        }
开发者ID:rid00z,项目名称:JellyBeanTracker,代码行数:30,代码来源:JellyBeanListPage.cs

示例12: SesionesPage

        public SesionesPage()
        {
            BindingContext = new EventoData();

            Title = "Sesiones";
            Icon = "tabsession.png";
            BackgroundImage = "background.png";

            StackLayout panel = new StackLayout
            {
                Spacing = 6,
            };

            ListView listaSesiones = new ListView();
            listaSesiones.SetBinding(ListView.ItemsSourceProperty, new Binding("Sessions", BindingMode.OneWay));
            listaSesiones.ItemTemplate = new DataTemplate(typeof(SessionCell));
            listaSesiones.RowHeight = 64;

            listaSesiones.ItemSelected += (sender, e) =>
            {
                var item = (Session)e.SelectedItem;
                SessionDetailPage sessionPage = new SessionDetailPage();
                sessionPage.BindingContext = item;
                Navigation.PushAsync(sessionPage);
            };

            panel.Children.Add(listaSesiones);
            Content = panel;
        }
开发者ID:palaniakasapu,项目名称:Xamarin,代码行数:29,代码来源:SesionesPage.cs

示例13: Issue1875

		public Issue1875()
		{
			Button loadData = new Button { Text = "Load", HorizontalOptions = LayoutOptions.FillAndExpand };
			ListView mainList = new ListView {
				VerticalOptions = LayoutOptions.FillAndExpand,
				HorizontalOptions = LayoutOptions.FillAndExpand
			};

			mainList.SetBinding (ListView.ItemsSourceProperty, "Items");

			_viewModel = new MainViewModel ();
			BindingContext = _viewModel;
			loadData.Clicked += async (sender, e) => {
				await LoadData ();
			};

			mainList.ItemAppearing += OnItemAppearing;

			Content = new StackLayout {
				Children = {
					loadData,
					mainList
				}
			};
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:25,代码来源:Issue1875.cs

示例14: SetContent

        /// <summary>
        /// Method that creates the page content
        /// </summary>
        public void SetContent()
        {
            var header = new Label
            {
                Text = "Vælg Takst",
                TextColor = Color.FromHex(Definitions.TextColor),
                FontSize = Definitions.HeaderFontSize,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                YAlign = TextAlignment.Center,
            };
            
            var backButton = new BackButton(SendBackMessage);
            // filler to make header is centered
            var filler = new Filler();
            // they need to be the same size.
            backButton.WidthRequest = backButton.WidthRequest - 40;
            filler.WidthRequest = backButton.WidthRequest;

            var headerstack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Color.FromHex(Definitions.PrimaryColor),
                HeightRequest = Definitions.HeaderHeight,
                Children =
                {
                    backButton,
                    header,
                    filler
                }
            };

            var list = new ListView
            {
                ItemTemplate = new DataTemplate(typeof(GenericCell)),
                SeparatorColor = Color.FromHex("#EE2D2D"),
                SeparatorVisibility = SeparatorVisibility.Default,
            };
            list.SetBinding(ListView.ItemsSourceProperty, TaxViewModel.TaxListProperty, BindingMode.TwoWay);

            list.ItemSelected += (sender, args) =>
            {
                var item = (GenericCellModel) args.SelectedItem;

                if (item == null) return;
                item.Selected = true;
                Selected = item;
                SendSelectedMessage();
            };

            var layout = new StackLayout
            {
                BackgroundColor = Color.FromHex(Definitions.BackgroundColor),
            };


            layout.Children.Add(headerstack);
            layout.Children.Add(list);

            this.Content = layout;
        }
开发者ID:os2indberetning,项目名称:OS2_Windows_Phone,代码行数:63,代码来源:TaxPage.cs

示例15: HomePageCS

		public HomePageCS ()
		{
			BindingContext = new HomePageViewModel ();

			var listView = new ListView ();
			listView.SetBinding (ItemsView<Cell>.ItemsSourceProperty, "People");
			listView.Behaviors.Add (new EventToCommandBehavior {
				EventName = "ItemSelected",
				Command = ((HomePageViewModel)BindingContext).OutputAgeCommand,
				Converter = new SelectedItemEventArgsToSelectedItemConverter ()
			});

			var selectedItemLabel = new Label ();
			selectedItemLabel.SetBinding (Label.TextProperty, "SelectedItemText");

			Content = new StackLayout { 
				Padding = new Thickness (0, 20, 0, 0),
				Children = {
					new Label {
						Text = "Behaviors Demo",
						FontAttributes = FontAttributes.Bold,
						HorizontalOptions = LayoutOptions.Center
					},
					listView,
					selectedItemLabel
				}
			};
		}
开发者ID:ChandrakanthBCK,项目名称:xamarin-forms-samples,代码行数:28,代码来源:HomePageCS.cs


注:本文中的ListView.SetBinding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。