public ContactsListPage() { var addContactButton = new ToolbarItem { Text = "+", AutomationId = AutomationIdConstants.AddContactButon }; addContactButton.Clicked += HandleAddContactButtonClicked; ToolbarItems.Add(addContactButton); _contactsListView = new Xamarin.Forms.ListView(ListViewCachingStrategy.RecycleElement) { ItemTemplate = new DataTemplate(typeof(ContactsListTextCell)), IsPullToRefreshEnabled = true, BackgroundColor = Color.Transparent, AutomationId = AutomationIdConstants.ContactsListView }; _contactsListView.ItemSelected += HandleItemSelected; _contactsListView.SetBinding(Xamarin.Forms.ListView.ItemsSourceProperty, nameof(ViewModel.AllContactsList)); _contactsListView.SetBinding(Xamarin.Forms.ListView.RefreshCommandProperty, nameof(ViewModel.RefreshCommand)); _contactsListView.SetBinding(Xamarin.Forms.ListView.IsRefreshingProperty, nameof(ViewModel.IsRefreshing)); var restoreDeletedContactsButton = new Button { Text = " Restore Deleted Contacts ", TextColor = ColorConstants.TextColor, AutomationId = AutomationIdConstants.RestoreDeletedContactsButton, BackgroundColor = new Color(ColorConstants.NavigationBarBackgroundColor.R, ColorConstants.NavigationBarBackgroundColor.G, ColorConstants.NavigationBarBackgroundColor.B, 0.25) }; restoreDeletedContactsButton.Clicked += HandleRestoreDeletedContactsButtonClicked; Title = PageTitleConstants.ContactsListPage; var relativeLayout = new RelativeLayout(); relativeLayout.Children.Add(_contactsListView, Constraint.Constant(0), Constraint.Constant(0), Constraint.RelativeToParent(parent => parent.Width), Constraint.RelativeToParent(parent => parent.Height)); relativeLayout.Children.Add(restoreDeletedContactsButton, Constraint.RelativeToParent(parent => parent.Width / 2 - getRestoreDeletedContactsButtonWidth(parent) / 2), Constraint.RelativeToParent(parent => parent.Height - getRestoreDeletedContactsButtonHeight(parent) - 10)); Content = relativeLayout; On <iOS>().SetUseSafeArea(true); double getRestoreDeletedContactsButtonHeight(RelativeLayout parent) => restoreDeletedContactsButton.Measure(parent.Width, parent.Height).Request.Height; double getRestoreDeletedContactsButtonWidth(RelativeLayout parent) => restoreDeletedContactsButton.Measure(parent.Width, parent.Height).Request.Width; }
void setup() { contractListView = new Xamarin.Forms.ListView(ListViewCachingStrategy.RecycleElement) { AutomationId = "ContractList", ItemTemplate = new DataTemplate(typeof(WorkflowInstanceViewCell)), IsPullToRefreshEnabled = true, SeparatorVisibility = SeparatorVisibility.None, HasUnevenRows = true, IsGroupingEnabled = false, BackgroundColor = Color.FromHex("E3E3E3") }; contractListView.SetBinding(ListView.ItemsSourceProperty, nameof(ViewModel.ContractInstances), BindingMode.TwoWay); contractListView.SetBinding(ListView.RefreshCommandProperty, nameof(ViewModel.RefreshContractsCommand)); contractListView.SetBinding(ListView.IsRefreshingProperty, nameof(ViewModel.IsBusy), BindingMode.TwoWay); //ToolbarItems.Add(new ToolbarItem("Filter", null, async () => await changePropertiesViewedAsync(), ToolbarItemOrder.Primary)); var relativeLayout = new RelativeLayout(); AddContractButton = new FabButton { Text = "", FontFamily = "FontAwesome", TextColor = Color.White, BackgroundColor = Constants.NavBarBackgroundColor, FontSize = 22, CornerRadius = 35, }; if (Device.RuntimePlatform.Equals(Device.Android)) { AddContractButton.Effects.Add(Effect.Resolve("Xamarin.FontAwesomeEffect")); } relativeLayout.Children.Add(contractListView, xConstraint: Constraint.Constant(0), yConstraint: Constraint.Constant(0), widthConstraint: Constraint.RelativeToParent(p => p.Width), heightConstraint: Constraint.RelativeToParent(p => p.Height)); relativeLayout.Children.Add(AddContractButton, xConstraint: Constraint.RelativeToParent(p => p.Width - 78), // padding is 12 yConstraint: Constraint.RelativeToParent(p => p.Height - 78), // padding is 12 widthConstraint: Constraint.Constant(70), heightConstraint: Constraint.Constant(70)); AddContractButton.SetBinding(IsVisibleProperty, "IsUserInitiator"); RootContent = relativeLayout; }
public iOSListViewWithCellPageCS() { var personDataTemplate = new DataTemplate(() => { var grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.7, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.3, GridUnitType.Star) }); var nameLabel = new Label(); var ageLabel = new Label { HorizontalOptions = LayoutOptions.End }; nameLabel.SetBinding(Label.TextProperty, "Name"); ageLabel.SetBinding(Label.TextProperty, "Age"); grid.Children.Add(nameLabel); grid.Children.Add(ageLabel, 1, 0); return(new ViewCell { View = grid }); }); var groupHeaderTemplate = new DataTemplate(() => { var label = new Label { Margin = new Thickness(10, 10), FontAttributes = FontAttributes.Bold }; label.SetBinding(Label.TextProperty, "Key"); var viewCell = new ViewCell { View = label }; viewCell.On <iOS>().SetDefaultBackgroundColor(Color.Teal); return(viewCell); }); var listView = new Xamarin.Forms.ListView { IsGroupingEnabled = true, ItemTemplate = personDataTemplate, GroupHeaderTemplate = groupHeaderTemplate }; listView.SetBinding(ItemsView <Xamarin.Forms.Cell> .ItemsSourceProperty, "GroupedEmployees"); listView.On <iOS>() .SetSeparatorStyle(SeparatorStyle.FullWidth) .SetRowAnimationsEnabled(false) .SetGroupHeaderStyle(GroupHeaderStyle.Grouped); Title = "ListView/Cell Platform-Specifics"; Content = new StackLayout { Margin = new Thickness(20), Children = { listView } }; BindingContext = new ListViewViewModel(20); }
public iOSPanGestureRecognizerPageCS() { Xamarin.Forms.Application.Current.On <iOS>().SetPanGestureRecognizerShouldRecognizeSimultaneously(true); var messageLabel = new Label { Text = "Scroll the list. If you touch the age Label, this Label will change", FontAttributes = FontAttributes.Bold }; var toggleButton = new Button { Text = "Toggle Simultaneous Gesture Recognition" }; toggleButton.Clicked += (sender, e) => Xamarin.Forms.Application.Current.On <iOS>().SetPanGestureRecognizerShouldRecognizeSimultaneously( !Xamarin.Forms.Application.Current.On <iOS>().GetPanGestureRecognizerShouldRecognizeSimultaneously()); var personDataTemplate = new DataTemplate(() => { var grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.7, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.3, GridUnitType.Star) }); var nameLabel = new Label(); nameLabel.SetBinding(Label.TextProperty, "Name"); var ageLabel = new Label { HorizontalOptions = LayoutOptions.End }; ageLabel.SetBinding(Label.TextProperty, "Age"); var panGestureRecognizer = new PanGestureRecognizer(); panGestureRecognizer.PanUpdated += (sender, e) => messageLabel.Text = $"panned x:{e.TotalX} y:{e.TotalY}";; ageLabel.GestureRecognizers.Add(panGestureRecognizer); grid.Children.Add(nameLabel); grid.Children.Add(ageLabel, 1, 0); return(new ViewCell { View = grid }); }); var listView = new Xamarin.Forms.ListView { IsGroupingEnabled = true, ItemTemplate = personDataTemplate }; listView.SetBinding(ItemsView <Cell> .ItemsSourceProperty, "GroupedEmployees"); listView.GroupDisplayBinding = new Binding("Key"); Title = "Pan Gesture Recognizer"; Content = new StackLayout { Margin = new Thickness(20), Children = { messageLabel, toggleButton, listView } }; BindingContext = new ListViewViewModel(); }
public AndroidListViewFastScrollPageCS() { var personDataTemplate = new DataTemplate(() => { var grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.7, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.3, GridUnitType.Star) }); var nameLabel = new Label(); var ageLabel = new Label { HorizontalOptions = LayoutOptions.End }; nameLabel.SetBinding(Label.TextProperty, "Name"); ageLabel.SetBinding(Label.TextProperty, "Age"); grid.Children.Add(nameLabel); grid.Children.Add(ageLabel, 1, 0); return(new Xamarin.Forms.ViewCell { View = grid }); }); var listView = new Xamarin.Forms.ListView { IsGroupingEnabled = true, ItemTemplate = personDataTemplate }; listView.SetBinding(ItemsView <Cell> .ItemsSourceProperty, "GroupedEmployees"); listView.GroupDisplayBinding = new Binding("Key"); listView.On <Android>().SetIsFastScrollEnabled(true); var button = new Xamarin.Forms.Button { Text = "Toggle FastScroll" }; button.Clicked += (sender, e) => { listView.On <Android>().SetIsFastScrollEnabled(!listView.On <Android>().IsFastScrollEnabled()); }; Title = "ListView FastScroll"; Content = new StackLayout { Margin = new Thickness(20), Children = { button, listView } }; BindingContext = new ListViewViewModel(); }
void Construct() { BindingContext = new RefreshViewModel(); var refreshView = new Xamarin.Forms.RefreshView { BackgroundColor = Color.Red, RefreshColor = Color.Yellow }; refreshView.SetBinding(Xamarin.Forms.RefreshView.CommandProperty, "RefreshCommand"); refreshView.SetBinding(Xamarin.Forms.RefreshView.IsRefreshingProperty, "IsRefreshing"); refreshView.On <WindowsOS>().SetRefreshPullDirection(RefreshPullDirection.BottomToTop); var listView = new Xamarin.Forms.ListView { ItemTemplate = new DataTemplate(() => { var stackLayout = new StackLayout { Orientation = StackOrientation.Horizontal }; var boxView = new BoxView { WidthRequest = 40 }; var infoLabel = new Xamarin.Forms.Label(); boxView.SetBinding(BoxView.ColorProperty, "Color"); infoLabel.SetBinding(Xamarin.Forms.Label.TextProperty, "Name"); stackLayout.Children.Add(boxView); stackLayout.Children.Add(infoLabel); return(new ViewCell { View = stackLayout }); }) }; listView.SetBinding(Xamarin.Forms.ListView.ItemsSourceProperty, "Items"); refreshView.Content = listView; Content = refreshView; }
public iOSListViewPageCS() { var personDataTemplate = new DataTemplate(() => { var grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.7, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.3, GridUnitType.Star) }); var nameLabel = new Label(); var ageLabel = new Label { HorizontalOptions = LayoutOptions.End }; nameLabel.SetBinding(Label.TextProperty, "Name"); ageLabel.SetBinding(Label.TextProperty, "Age"); grid.Children.Add(nameLabel); grid.Children.Add(ageLabel, 1, 0); return(new ViewCell { View = grid }); }); var listView = new Xamarin.Forms.ListView { IsGroupingEnabled = true, ItemTemplate = personDataTemplate }; listView.SetBinding(ItemsView <Cell> .ItemsSourceProperty, "GroupedEmployees"); listView.GroupDisplayBinding = new Binding("Key"); listView.On <iOS>().SetSeparatorStyle(SeparatorStyle.FullWidth); Title = "ListView FullWidth Separators"; Content = new StackLayout { Margin = new Thickness(20), Children = { listView } }; BindingContext = new ListViewViewModel(); }
public AndroidViewCellPageCS() { Button button = new Button { Text = "Toggle Legacy Mode" }; button.SetBinding(Button.CommandProperty, "ToggleLegacyMode"); DataTemplate oneItemTemplate = new DataTemplate(() => { Label label = new Label(); label.SetBinding(Label.TextProperty, "Text"); ViewCell viewCell = new ViewCell { View = label }; button.Clicked += (s, e) => { viewCell.On <Android>().SetIsContextActionsLegacyModeEnabled(!viewCell.On <Android>().GetIsContextActionsLegacyModeEnabled()); }; MenuItem menuItem = new MenuItem(); menuItem.SetBinding(MenuItem.TextProperty, "Item1Text"); viewCell.ContextActions.Add(menuItem); return(viewCell); }); DataTemplate twoItemsTemplate = new DataTemplate(() => { Label label = new Label(); label.SetBinding(Label.TextProperty, "Text"); ViewCell viewCell = new ViewCell { View = label }; button.Clicked += (s, e) => { viewCell.On <Android>().SetIsContextActionsLegacyModeEnabled(!viewCell.On <Android>().GetIsContextActionsLegacyModeEnabled()); }; MenuItem menuItem1 = new MenuItem(); menuItem1.SetBinding(MenuItem.TextProperty, "Item1Text"); MenuItem menuItem2 = new MenuItem(); menuItem2.SetBinding(MenuItem.TextProperty, "Item2Text"); viewCell.ContextActions.Add(menuItem1); viewCell.ContextActions.Add(menuItem2); return(viewCell); }); ItemDataTemplateSelector itemDataTemplateSelector = new ItemDataTemplateSelector { OneItemTemplate = oneItemTemplate, TwoItemsTemplate = twoItemsTemplate }; ListView listView = new ListView { ItemTemplate = itemDataTemplateSelector }; listView.SetBinding(ItemsView <Cell> .ItemsSourceProperty, "Items"); BindingContext = new AndroidViewCellPageViewModel(); Title = "ViewCell Context Actions"; Content = new StackLayout { Children = { new StackLayout { Margin = new Thickness(20), Children = { button, listView } } } }; }
public WindowsListViewPageCS() { var personDataTemplate = new DataTemplate(() => { var grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.7, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(0.3, GridUnitType.Star) }); var nameLabel = new Xamarin.Forms.Label(); var ageLabel = new Xamarin.Forms.Label { HorizontalOptions = LayoutOptions.Center }; nameLabel.SetBinding(Xamarin.Forms.Label.TextProperty, "Name"); ageLabel.SetBinding(Xamarin.Forms.Label.TextProperty, "Age"); var tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.Tapped += async(sender, e) => { await DisplayAlert("Tap Gesture Recognizer", "Tapped event fired.", "OK"); }; nameLabel.GestureRecognizers.Add(tapGestureRecognizer); grid.Children.Add(nameLabel); grid.Children.Add(ageLabel, 1, 0); return(new ViewCell { View = grid }); }); _listView = new Xamarin.Forms.ListView { IsGroupingEnabled = true, ItemTemplate = personDataTemplate }; _listView.SetBinding(ItemsView <Cell> .ItemsSourceProperty, "GroupedEmployees"); _listView.GroupDisplayBinding = new Binding("Key"); _listView.ItemTapped += async(sender, e) => { await DisplayAlert("Item Tapped", "ItemTapped event fired.", "OK"); }; _listView.On <Windows>().SetSelectionMode(ListViewSelectionMode.Inaccessible); var button = new Button { Text = "Toggle SelectionMode" }; button.Clicked += (sender, e) => { switch (_listView.On <Windows>().GetSelectionMode()) { case ListViewSelectionMode.Accessible: _listView.On <Windows>().SetSelectionMode(ListViewSelectionMode.Inaccessible); break; case ListViewSelectionMode.Inaccessible: _listView.On <Windows>().SetSelectionMode(ListViewSelectionMode.Accessible); break; } UpdateLabel(); }; _label = new Xamarin.Forms.Label { HorizontalOptions = LayoutOptions.Center }; Title = "ListView Selection Mode"; Content = new StackLayout { Margin = new Thickness(20), Children = { _listView, button, _label } }; BindingContext = new ListViewViewModel(); UpdateLabel(); }
public EventbriteViewPage() { Title = "Eventbrite"; BackgroundColor = Color.White; var foursquareViewModel = new EventbriteViewModel(); BindingContext = foursquareViewModel; var pageTitleLabel = new Label { Text = "Eventbrite", TextColor = Color.Gray, FontSize = 24 }; var dataTemplate = new DataTemplate(() => { var eventNameLabel = new Label { TextColor = Color.FromHex("#FF8832"), FontSize = 20 }; eventNameLabel.SetBinding(Label.TextProperty, new Binding("Name.Text")); var eventStartLabel = new Label { TextColor = Color.Gray, FontSize = 14 }; eventStartLabel.SetBinding(Label.TextProperty, new Binding("Start.Utc")); var eventEndLabel = new Label { TextColor = Color.Gray, FontSize = 14 }; eventEndLabel.SetBinding(Label.TextProperty, new Binding("End.Utc")); var eventDescriptionLabel = new Label { FontSize = 14, TextColor = Color.Black, HeightRequest = 100, }; eventDescriptionLabel.SetBinding(Label.TextProperty, new Binding("Description.Text")); var eventAddressLabel = new Label { FontSize = 14, TextColor = Color.Gray, }; eventAddressLabel.SetBinding(Label.TextProperty, new Binding("Venue.Address.Localized_Address_Display")); var logoImage = new Image { WidthRequest = 120, HeightRequest = 65, VerticalOptions = LayoutOptions.Start, }; logoImage.SetBinding(Image.SourceProperty, new Binding("Logo.Url")); return(new ViewCell { View = new StackLayout { Orientation = StackOrientation.Vertical, Padding = new Thickness(0, 5, 0, 10), Children = { new StackLayout { Orientation = StackOrientation.Horizontal, Children = { logoImage, eventNameLabel, } }, eventAddressLabel, new StackLayout { Orientation = StackOrientation.Horizontal, Children = { eventStartLabel, eventEndLabel } }, eventDescriptionLabel, } } }); }); var listView = new ListView { HasUnevenRows = true }; listView.SetBinding(ListView.ItemsSourceProperty, "EventbriteEvents.Events"); listView.ItemTemplate = dataTemplate; Content = new StackLayout { Padding = new Thickness(5, 10), Children = { pageTitleLabel, listView } }; }