■ BindableLayout 엘리먼트의 ItemsSource/ItemTemplate 첨부 속성을 사용하는 방법을 보여준다.
▶ Employee.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
namespace TestProject; public class Employee { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public int ID { get; set; } #endregion #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion } |
▶ EmployeeCollection.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
namespace TestProject { /// <summary> /// 직원 컬렉션 /// </summary> public class EmployeeCollection : List<Employee> { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - EmployeeCollection() /// <summary> /// 생성자 /// </summary> public EmployeeCollection() { Add(new Employee { ID = 1, Name = "홍길동" }); Add(new Employee { ID = 2, Name = "김철수" }); Add(new Employee { ID = 3, Name = "이영희" }); } #endregion } } |
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:TestProject"> <ContentPage.Resources> <local:EmployeeCollection x:Key="EmployeeCollectionKey" /> </ContentPage.Resources> <StackLayout HorizontalOptions="Center" VerticalOptions="Center" BindableLayout.ItemsSource="{StaticResource EmployeeCollectionKey}"> <BindableLayout.ItemTemplate> <DataTemplate> <HorizontalStackLayout> <Label Text="{Binding ID}" /> <Label Margin="10,0,0,0" Text="{Binding Name}" /> </HorizontalStackLayout> </DataTemplate> </BindableLayout.ItemTemplate> </StackLayout> </ContentPage> |