Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class App : Application
- {
- public App()
- {
- // The root page of your application
- MainPage = new MainPage
- {
- BindingContext = new MainPageViewModel()
- };
- }
- protected override void OnStart()
- {
- // Handle when your app starts
- }
- protected override void OnSleep()
- {
- // Handle when your app sleeps
- }
- protected override void OnResume()
- {
- // Handle when your app resumes
- }
- }
- public class MainPageViewModel
- {
- public ObservableCollection<ItemViewModel> Items { get; private set; }
- public MainPageViewModel()
- {
- Items = new ObservableCollection<ItemViewModel>()
- {
- new ItemViewModel("teste1"),
- new ItemViewModel("teste2"),
- new ItemViewModel("teste3"),
- };
- }
- }
- public class ItemViewModel
- {
- public string Name { get; }
- public ItemViewModel(string name)
- {
- if (name == null) throw new ArgumentNullException(nameof(name));
- Name = name;
- }
- }
- <?xml version="1.0" encoding="utf-8" ?>
- <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
- xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
- x:Class="TestApp2.MainPage">
- <ListView ItemsSource="{Binding Items}">
- <ListView.ItemTemplate>
- <DataTemplate x:Name="ItemDataTemplate">
- <StackLayout Orientation="Horizontal">
- <Label Text="{Binding Name}" />
- </StackLayout>
- </DataTemplate>
- </ListView.ItemTemplate>
- </ListView>
- </ContentPage>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement