Advertisement
Guest User

Untitled

a guest
Jan 30th, 2016
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. public class App : Application
  2. {
  3. public App()
  4. {
  5. // The root page of your application
  6. MainPage = new MainPage
  7. {
  8. BindingContext = new MainPageViewModel()
  9. };
  10. }
  11.  
  12. protected override void OnStart()
  13. {
  14. // Handle when your app starts
  15. }
  16.  
  17. protected override void OnSleep()
  18. {
  19. // Handle when your app sleeps
  20. }
  21.  
  22. protected override void OnResume()
  23. {
  24. // Handle when your app resumes
  25. }
  26. }
  27.  
  28. public class MainPageViewModel
  29. {
  30. public ObservableCollection<ItemViewModel> Items { get; private set; }
  31.  
  32. public MainPageViewModel()
  33. {
  34. Items = new ObservableCollection<ItemViewModel>()
  35. {
  36. new ItemViewModel("teste1"),
  37. new ItemViewModel("teste2"),
  38. new ItemViewModel("teste3"),
  39. };
  40. }
  41. }
  42.  
  43. public class ItemViewModel
  44. {
  45. public string Name { get; }
  46.  
  47. public ItemViewModel(string name)
  48. {
  49. if (name == null) throw new ArgumentNullException(nameof(name));
  50. Name = name;
  51. }
  52. }
  53.  
  54. <?xml version="1.0" encoding="utf-8" ?>
  55. <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
  56. xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  57. x:Class="TestApp2.MainPage">
  58. <ListView ItemsSource="{Binding Items}">
  59. <ListView.ItemTemplate>
  60. <DataTemplate x:Name="ItemDataTemplate">
  61. <StackLayout Orientation="Horizontal">
  62. <Label Text="{Binding Name}" />
  63. </StackLayout>
  64. </DataTemplate>
  65. </ListView.ItemTemplate>
  66. </ListView>
  67. </ContentPage>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement