Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
- xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
- xmlns:local="clr-namespace:TestXamarin"
- x:Class="TestXamarin.MainPage">
- <ContentPage.BindingContext>
- <local:MyViewModel />
- </ContentPage.BindingContext>
- <StackLayout>
- <ScrollView>
- <CollectionView ItemsSource="{Binding ResponseResponses}" SelectionMode="Single">
- <CollectionView.ItemTemplate>
- <DataTemplate>
- <StackLayout>
- <StackLayout.GestureRecognizers>
- <TapGestureRecognizer
- Command="{Binding SearchCommand}"
- NumberOfTapsRequired="1" />
- </StackLayout.GestureRecognizers>
- <Label Grid.Row="0" Text="{Binding Username}" />
- </StackLayout>
- </DataTemplate>
- </CollectionView.ItemTemplate>
- </CollectionView>
- </ScrollView>
- </StackLayout>
- </ContentPage>
- ///////////////
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Input;
- using Xamarin.Forms;
- namespace TestXamarin
- {
- public partial class MainPage : ContentPage
- {
- public MainPage()
- {
- InitializeComponent();
- }
- }
- public class MyViewModel
- {
- public MyViewModel()
- {
- var command = new Command(_ => ResponseResponses.Add(new SearchResponse("e", null)));
- ResponseResponses = new ObservableCollection<SearchResponse>
- {
- new SearchResponse("Test", command),
- new SearchResponse("Test2", command),
- new SearchResponse("Test3", command),
- };
- }
- public ObservableCollection<SearchResponse> ResponseResponses { get; set; }
- }
- public class SearchResponse
- {
- public SearchResponse(string username, ICommand command)
- {
- Username = username;
- SearchCommand = command;
- }
- public string Username { get; }
- public ICommand SearchCommand { get; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement