■ x:TypeArguments 속성에서 제네릭 타입 인자로 단일 객체 타입을 사용하는 방법을 보여준다.
▶ MonkeyModel.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 28 29 30 31 32 33 34 35 36 37 |
namespace TestProject; /// <summary> /// 원숭이 모델 /// </summary> public class MonkeyModel { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 이미지 URL - ImageURL /// <summary> /// 이미지 URL /// </summary> public string ImageURL { get; set; } #endregion #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion #region 서식지 - Location /// <summary> /// 서식지 /// </summary> public string Location { get; set; } #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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
<?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:scg="clr-namespace:System.Collections.Generic;assembly=netstandard" xmlns:local="clr-namespace:TestProject"> <CollectionView Margin="10"> <CollectionView.ItemsSource> <scg:List x:TypeArguments="local:MonkeyModel"> <local:MonkeyModel ImageURL="https://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Papio_anubis_%28Serengeti%2C_2009%29.jpg/200px-Papio_anubis_%28Serengeti%2C_2009%29.jpg" Name="Baboon" Location="Africa and Asia" /> <local:MonkeyModel ImageURL="https://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Capuchin_Costa_Rica.jpg/200px-Capuchin_Costa_Rica.jpg" Name="Capuchin Monkey" Location="Central and South America" /> <local:MonkeyModel ImageURL="https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/BlueMonkey.jpg/220px-BlueMonkey.jpg" Name="Blue Monkey" Location="Central and East Africa" /> </scg:List> </CollectionView.ItemsSource> <CollectionView.ItemTemplate> <DataTemplate> <Grid Padding="10" RowDefinitions="Auto,Auto" ColumnDefinitions="Auto,10,Auto"> <Image Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" WidthRequest="60" HeightRequest="60" Aspect="AspectFill" Source="{Binding ImageURL}" /> <Label Grid.Column="2" FontSize="16" FontAttributes="Bold" Text="{Binding Name}" /> <Label Grid.Row="1" Grid.Column="2" VerticalOptions="End" FontAttributes="Italic" Text="{Binding Location}" /> </Grid> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </ContentPage> |