Xamarin形成listview数据绑定到对象

时间:2016-06-17 09:26:16

标签: c# xamarin.forms

是否可以绑定到对象而不是列表视图中的属性。例如:

public ObservableCollection<Employee> employees = new ObservableCollection<Employee>(); 
        public EmployeeListPage()
        {                      
            employees.Add(new Employee { DisplayName = "Rob Finnerty" });
            employees.Add(new Employee { DisplayName = "Bill Wrestler" });
            employees.Add(new Employee { DisplayName = "Dr. Geri-Beth Hooper" });
            employees.Add(new Employee { DisplayName = "Dr. Keith Joyce-Purdy" });
            employees.Add(new Employee { DisplayName = "Sheri Spruce" });
            employees.Add(new Employee { DisplayName = "Burt Indybrick" });       
        }

 <ListView ItemSource="{Binding employees}" x:Name="emView">
      <ListView.ItemTemplate>
        <DataTemplate>
          <ViewCell>
              <b:CustomView Employee="{Binding .}"/>
          </ViewCell>                   
        </DataTemplate>                     
      </ListView.ItemTemplate>
    </ListView>`

0 个答案:

没有答案