Advertisement
Guest User

Untitled

a guest
Oct 19th, 2021
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  4. xmlns:local="clr-namespace:TestXamarin"
  5. x:Class="TestXamarin.MainPage">
  6.  
  7. <ContentPage.BindingContext>
  8. <local:MyViewModel />
  9. </ContentPage.BindingContext>
  10.  
  11. <StackLayout>
  12. <ScrollView>
  13. <CollectionView ItemsSource="{Binding ResponseResponses}" SelectionMode="Single">
  14. <CollectionView.ItemTemplate>
  15. <DataTemplate>
  16. <StackLayout>
  17. <StackLayout.GestureRecognizers>
  18. <TapGestureRecognizer
  19. Command="{Binding SearchCommand}"
  20. NumberOfTapsRequired="1" />
  21. </StackLayout.GestureRecognizers>
  22. <Label Grid.Row="0" Text="{Binding Username}" />
  23. </StackLayout>
  24. </DataTemplate>
  25. </CollectionView.ItemTemplate>
  26. </CollectionView>
  27. </ScrollView>
  28. </StackLayout>
  29.  
  30. </ContentPage>
  31.  
  32.  
  33.  
  34. ///////////////
  35.  
  36.  
  37.  
  38.  
  39. using System;
  40. using System.Collections.Generic;
  41. using System.Collections.ObjectModel;
  42. using System.Linq;
  43. using System.Text;
  44. using System.Threading.Tasks;
  45. using System.Windows.Input;
  46. using Xamarin.Forms;
  47.  
  48. namespace TestXamarin
  49. {
  50. public partial class MainPage : ContentPage
  51. {
  52. public MainPage()
  53. {
  54. InitializeComponent();
  55. }
  56. }
  57.  
  58. public class MyViewModel
  59. {
  60. public MyViewModel()
  61. {
  62. var command = new Command(_ => ResponseResponses.Add(new SearchResponse("e", null)));
  63. ResponseResponses = new ObservableCollection<SearchResponse>
  64. {
  65. new SearchResponse("Test", command),
  66. new SearchResponse("Test2", command),
  67. new SearchResponse("Test3", command),
  68. };
  69. }
  70.  
  71. public ObservableCollection<SearchResponse> ResponseResponses { get; set; }
  72. }
  73.  
  74. public class SearchResponse
  75. {
  76. public SearchResponse(string username, ICommand command)
  77. {
  78. Username = username;
  79. SearchCommand = command;
  80. }
  81.  
  82. public string Username { get; }
  83.  
  84. public ICommand SearchCommand { get; }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement