public MainPage() { InitializeComponent(); CrossSettings.Current.AddOrUpdateValue("AdData", ""); string curUserVM_json = CrossSettings.Current.GetValueOrDefault("current_user", null); if (String.IsNullOrEmpty(curUserVM_json)) { ToSignIn(); } else { UserViewModel curUserVM = JsonConvert.DeserializeObject <UserViewModel>(curUserVM_json); UserNameToolBar.Text = $"{curUserVM.FirstName} {curUserVM.LastName}"; //SignInToolBar.Text = "Выйти"; StackLayout signedSL = new StackLayout { Margin = new Thickness(10, 0), Padding = new Thickness(10) }; Label AdsLabel = new Label { Text = "Ваши автомобили", TextColor = Color.Black, Margin = new Thickness(0, 10), FontAttributes = FontAttributes.Bold, HorizontalOptions = LayoutOptions.CenterAndExpand, FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Button)) }; signedSL.Children.Add(AdsLabel); List <AdViewModel> AdVMs = AdSQLiteH.GetByUser(curUserVM.Id); if (AdVMs.Count == 0) { Label AdsListLabel = new Label { Text = "У вас пока нет объявлений", TextColor = Color.Black, Margin = new Thickness(0, 10), HorizontalOptions = LayoutOptions.CenterAndExpand, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Button)) }; signedSL.Children.Add(AdsListLabel); } else { CollectionView AdCollectionView = new CollectionView(); AdCollectionView.ItemsSource = AdVMs; AdCollectionView.SelectionMode = SelectionMode.Single; AdCollectionView.SelectionChanged += ToAdPage_ItemSelected; AdCollectionView.ItemTemplate = new DataTemplate(() => { StackLayout stackLayout = new StackLayout { BackgroundColor = Color.White, Padding = new Thickness(0, 0, 0, 5) }; Frame frame = new Frame { CornerRadius = 10, BorderColor = Color.FromHex("#e1e1e1"), HasShadow = true, BackgroundColor = Color.FromHex("#f5f5f5"), Padding = new Thickness(5), Margin = new Thickness(10, 5) }; Grid grid = new Grid() { BackgroundColor = Color.FromHex("#f5f5f5") }; grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); Image image = new Image { Aspect = Aspect.AspectFill, HeightRequest = 60, WidthRequest = 100, Source = "empty_CAR_FRONT_LEFT_pencil.png" }; Label InfoLabel_1 = new Label { FontAttributes = FontAttributes.Bold, VerticalOptions = LayoutOptions.Center, TextColor = Color.Black, HorizontalOptions = LayoutOptions.StartAndExpand }; InfoLabel_1.SetBinding(Label.TextProperty, "InfoLabel_1"); Label InfoLabel_2 = new Label { FontAttributes = FontAttributes.Bold, VerticalOptions = LayoutOptions.Center, TextColor = Color.FromHex("#428bca"), HorizontalOptions = LayoutOptions.StartAndExpand }; InfoLabel_2.SetBinding(Label.TextProperty, "InfoLabel_2"); Label InfoLabel_3 = new Label { FontAttributes = FontAttributes.Italic, VerticalOptions = LayoutOptions.Center, TextColor = Color.Black, HorizontalOptions = LayoutOptions.StartAndExpand }; InfoLabel_3.SetBinding(Label.TextProperty, "InfoLabel_3"); Grid.SetRowSpan(image, 3); grid.Children.Add(image); grid.Children.Add(InfoLabel_1, 1, 0); grid.Children.Add(InfoLabel_2, 1, 1); grid.Children.Add(InfoLabel_3, 1, 2); SwipeView AdSwipeView = new SwipeView(); SwipeItem sendSwipeItem = new SwipeItem { IconImageSource = "send.png", BackgroundColor = Color.FromHex("#428bca") }; sendSwipeItem.SetBinding(MenuItem.CommandProperty, new Binding("BindingContext.SendCommand", source: AdCollectionView)); sendSwipeItem.SetBinding(MenuItem.CommandParameterProperty, "."); SwipeItem deleteSwipeItem = new SwipeItem { IconImageSource = "delete.png", BackgroundColor = Color.FromHex("#a94442") }; deleteSwipeItem.SetBinding(MenuItem.CommandProperty, new Binding("BindingContext.DeleteCommand", source: AdCollectionView)); deleteSwipeItem.SetBinding(MenuItem.CommandParameterProperty, "."); AdSwipeView.RightItems = new SwipeItems { sendSwipeItem, deleteSwipeItem }; AdSwipeView.Content = grid; frame.Content = AdSwipeView; stackLayout.Children.Add(frame); return(stackLayout); }); signedSL.Children.Add(AdCollectionView); } Button AddAdvertisement = new Button { ImageSource = "wplus.png", Text = "Добавить автомобиль", BackgroundColor = Color.FromHex("#5cb85c"), TextColor = Color.White, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Button)), FontAttributes = FontAttributes.Bold, BorderWidth = 1, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.EndAndExpand, Margin = new Thickness(0, 20), Padding = new Thickness(50, 0) }; AddAdvertisement.Clicked += AddAd_Clicked; signedSL.Children.Add(AddAdvertisement); this.Content = signedSL; } }
public SwipeViewDemoPage() { Label header = new Label { Text = "SwipeView", FontSize = 50, FontAttributes = FontAttributes.Bold, HorizontalOptions = LayoutOptions.Center }; // Create the CollectionView. CollectionView collectionView = new CollectionView(); // Define template for displaying each item. // (Argument of DataTemplate constructor is called for each item collectionView.ItemTemplate = new DataTemplate(() => { SwipeView swipeView = new SwipeView(); SwipeItem swipeItem = new SwipeItem { Text = "Delete", IconImageSource = "delete.png", BackgroundColor = Color.LightPink }; swipeItem.SetBinding(MenuItem.CommandProperty, new Binding("BindingContext.DeleteCommand", source: collectionView)); swipeItem.SetBinding(MenuItem.CommandParameterProperty, "."); swipeView.LeftItems = new SwipeItems { swipeItem }; Grid grid = new Grid { BackgroundColor = Color.White, Padding = 10 }; grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); Image image = new Image { Aspect = Aspect.AspectFill, HeightRequest = 60, WidthRequest = 60 }; image.SetBinding(Image.SourceProperty, "ImageUrl"); Label nameLabel = new Label { FontAttributes = FontAttributes.Bold }; nameLabel.SetBinding(Label.TextProperty, "Name"); Label locationLabel = new Label { FontAttributes = FontAttributes.Italic, VerticalOptions = LayoutOptions.End, LineBreakMode = LineBreakMode.TailTruncation }; locationLabel.SetBinding(Label.TextProperty, "Location"); Grid.SetRowSpan(image, 2); grid.Children.Add(image); grid.Children.Add(nameLabel, 1, 0); grid.Children.Add(locationLabel, 1, 1); swipeView.Content = grid; return(swipeView); }); collectionView.SetBinding(ItemsView.ItemsSourceProperty, "Monkeys"); // Build the page. Title = "SwipeView Demo"; Content = new StackLayout { Margin = new Thickness(20), Children = { header, collectionView } }; CreateMonkeyCollection(); BindingContext = this; }
static SwipeView LoadTemplate() { var beaconFundingImage = new Image { Source = "beaconfundingicon", HeightRequest = _rowHeight }; var topicTitleLabel = new Label { Text = "Topic", FontAttributes = FontAttributes.Bold, VerticalTextAlignment = TextAlignment.End }; var topicDescriptionLabel = new Label { VerticalTextAlignment = TextAlignment.Start }; topicDescriptionLabel.SetBinding(Label.TextProperty, nameof(OpportunityModel.Topic)); var companyTitleLabel = new Label { Text = "Company", FontAttributes = FontAttributes.Bold, VerticalTextAlignment = TextAlignment.End }; var companyDescriptionLabel = new Label { VerticalTextAlignment = TextAlignment.Start }; companyDescriptionLabel.SetBinding(Label.TextProperty, nameof(OpportunityModel.Company)); var leaseAmountTitleLabel = new Label { Text = "Lease Amount", FontAttributes = FontAttributes.Bold, VerticalTextAlignment = TextAlignment.End }; var leaseAmountDescriptionLabel = new Label { VerticalTextAlignment = TextAlignment.Start }; leaseAmountDescriptionLabel.SetBinding(Label.TextProperty, nameof(OpportunityModel.LeaseAmountAsCurrency)); var ownerTitleLabel = new Label { Text = "Owner", FontAttributes = FontAttributes.Bold, VerticalTextAlignment = TextAlignment.End }; var ownerDescriptionLabel = new Label { VerticalTextAlignment = TextAlignment.Start }; ownerDescriptionLabel.SetBinding(Label.TextProperty, nameof(OpportunityModel.Owner)); var grid = new Grid { BackgroundColor = Color.White, Padding = new Thickness(5, 0, 0, 0), ColumnSpacing = 20, RowDefinitions = { new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, new RowDefinition { Height = new GridLength(1, GridUnitType.Star) } }, ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(_rowHeight / 3, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) } } }; grid.Children.Add(beaconFundingImage, 0, 0); Grid.SetRowSpan(beaconFundingImage, 2); grid.Children.Add(topicTitleLabel, 1, 0); grid.Children.Add(topicDescriptionLabel, 1, 1); if (Device.Idiom != TargetIdiom.Phone) { grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); grid.Children.Add(companyTitleLabel, 2, 0); grid.Children.Add(companyDescriptionLabel, 2, 1); grid.Children.Add(leaseAmountTitleLabel, 3, 0); grid.Children.Add(leaseAmountDescriptionLabel, 3, 1); grid.Children.Add(ownerTitleLabel, 4, 0); grid.Children.Add(ownerDescriptionLabel, 4, 1); } var deleteSwipeItem = new SwipeItem { Text = "Delete", BackgroundColor = Color.Red, Command = new AsyncCommand <string>(ExecuteSwipeToDeleteCommand) }; deleteSwipeItem.SetBinding(SwipeItem.CommandParameterProperty, nameof(OpportunityModel.Topic)); var swipeView = new SwipeView { RightItems = { deleteSwipeItem }, Content = grid, Margin = new Thickness(0, 5, 0, 15) }; return(swipeView); }