■ CollectionView 엘리먼트의 FlowDirection 속성을 사용해 오른쪽에서 왼쪽 레이아웃을 설정하는 방법을 보여준다. ▶ Monkey.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 Monkey { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion #region 위치 - Location /// <summary> /// 위치 /// </summary> public string Location { get; set; } #endregion #region 이미지 URL - ImageURL /// <summary> /// 이미지 URL /// </summary> public string ImageURL { get; set; } #endregion } |
▶ ImageSourceConverter.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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
using System.Globalization; namespace TestProject; /// <summary> /// 이미지 URL→이미지 소스 변환자 /// </summary> public class ImageSourceConverter : IValueConverter { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 변환하기 - Convert(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>변환 값</returns> public object Convert(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { string imageURL = sourceValue as string; if(string.IsNullOrWhiteSpace(imageURL)) { return null; } return ImageSource.FromUri(new Uri(imageURL)); } #endregion #region 역변환하기 - ConvertBack(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 역변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>역변환 값</returns> public object ConvertBack(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { throw new NotImplementedException(); } #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
|
<?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:ImageSourceConverter x:Key="ImageSourceConverterKey" /> </ContentPage.Resources> <CollectionView x:Name="collectionView" FlowDirection="RightToLeft"> <CollectionView.ItemTemplate> <DataTemplate> <Grid Padding="10" RowDefinitions="Auto" ColumnDefinitions="Auto,10,*"> <Image Grid.Column="0" WidthRequest="60" HeightRequest="60" Aspect="AspectFill" Source="{Binding ImageURL, Converter={StaticResource ImageSourceConverterKey}}" /> <StackLayout Grid.Column="2"> <Label FontAttributes="Bold" FontSize="16" Text="{Binding Name}" /> <Label VerticalOptions="End" FontAttributes="Italic" Text="{Binding Location}" /> </StackLayout> </Grid> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </ContentPage> |
▶
더 읽기
■ GridItemsLayout 엘리먼트의 HorizontalItemSpacing/VerticalItemSpacing 속성을 사용해 ColletionView 객체의 항목 간격을 설정하는 방법을 보여준다. ▶ Monkey.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 Monkey { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion #region 위치 - Location /// <summary> /// 위치 /// </summary> public string Location { get; set; } #endregion #region 이미지 URL - ImageURL /// <summary> /// 이미지 URL /// </summary> public string ImageURL { get; set; } #endregion } |
▶ ImageSourceConverter.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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
using System.Globalization; namespace TestProject; /// <summary> /// 이미지 URL→이미지 소스 변환자 /// </summary> public class ImageSourceConverter : IValueConverter { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 변환하기 - Convert(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>변환 값</returns> public object Convert(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { string imageURL = sourceValue as string; if(string.IsNullOrWhiteSpace(imageURL)) { return null; } return ImageSource.FromUri(new Uri(imageURL)); } #endregion #region 역변환하기 - ConvertBack(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 역변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>역변환 값</returns> public object ConvertBack(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { throw new NotImplementedException(); } #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
|
<?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:ImageSourceConverter x:Key="ImageSourceConverterKey" /> </ContentPage.Resources> <CollectionView x:Name="collectionView"> <CollectionView.ItemsLayout> <GridItemsLayout Orientation="Vertical" Span="2" HorizontalItemSpacing="30" VerticalItemSpacing="20" /> </CollectionView.ItemsLayout> <CollectionView.ItemTemplate> <DataTemplate> <Grid Padding="10" RowDefinitions="Auto" ColumnDefinitions="Auto,10,*"> <Image Grid.Column="0" WidthRequest="60" HeightRequest="60" Aspect="AspectFill" Source="{Binding ImageURL, Converter={StaticResource ImageSourceConverterKey}}" /> <StackLayout Grid.Column="2"> <Label FontAttributes="Bold" FontSize="16" Text="{Binding Name}" /> <Label VerticalOptions="End" FontAttributes="Italic" Text="{Binding Location}" /> </StackLayout> </Grid> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </ContentPage> |
더 읽기
■ LinearItemsLayout 엘리먼트의 ItemSpacing 속성을 사용해 ColletionView 객체의 항목 간격을 설정하는 방법을 보여준다. ▶ Monkey.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 Monkey { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion #region 위치 - Location /// <summary> /// 위치 /// </summary> public string Location { get; set; } #endregion #region 이미지 URL - ImageURL /// <summary> /// 이미지 URL /// </summary> public string ImageURL { get; set; } #endregion } |
▶ ImageSourceConverter.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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
using System.Globalization; namespace TestProject; /// <summary> /// 이미지 URL→이미지 소스 변환자 /// </summary> public class ImageSourceConverter : IValueConverter { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 변환하기 - Convert(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>변환 값</returns> public object Convert(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { string imageURL = sourceValue as string; if(string.IsNullOrWhiteSpace(imageURL)) { return null; } return ImageSource.FromUri(new Uri(imageURL)); } #endregion #region 역변환하기 - ConvertBack(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 역변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>역변환 값</returns> public object ConvertBack(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { throw new NotImplementedException(); } #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
|
<?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:ImageSourceConverter x:Key="ImageSourceConverterKey" /> </ContentPage.Resources> <CollectionView x:Name="collectionView"> <CollectionView.ItemsLayout> <LinearItemsLayout Orientation="Vertical" ItemSpacing="20" /> </CollectionView.ItemsLayout> <CollectionView.ItemTemplate> <DataTemplate> <Grid Padding="10" RowDefinitions="Auto" ColumnDefinitions="Auto,10,*"> <Image Grid.Column="0" WidthRequest="60" HeightRequest="60" Aspect="AspectFill" Source="{Binding ImageURL, Converter={StaticResource ImageSourceConverterKey}}" /> <StackLayout Grid.Column="2"> <Label FontAttributes="Bold" FontSize="16" Text="{Binding Name}" /> <Label VerticalOptions="End" FontAttributes="Italic" Text="{Binding Location}" /> </StackLayout> </Grid> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </ContentPage> |
더 읽기
■ GridItemsLayout 엘리먼트의 Orientation/Span 속성을 사용해 수평 그리드 레이아웃을 설정하는 방법을 보여준다. ▶ Monkey.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 Monkey { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion #region 위치 - Location /// <summary> /// 위치 /// </summary> public string Location { get; set; } #endregion #region 이미지 URL - ImageURL /// <summary> /// 이미지 URL /// </summary> public string ImageURL { get; set; } #endregion } |
▶ ImageSourceConverter.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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
using System.Globalization; namespace TestProject; /// <summary> /// 이미지 URL→이미지 소스 변환자 /// </summary> public class ImageSourceConverter : IValueConverter { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 변환하기 - Convert(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>변환 값</returns> public object Convert(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { string imageURL = sourceValue as string; if(string.IsNullOrWhiteSpace(imageURL)) { return null; } return ImageSource.FromUri(new Uri(imageURL)); } #endregion #region 역변환하기 - ConvertBack(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 역변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>역변환 값</returns> public object ConvertBack(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { throw new NotImplementedException(); } #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
|
<?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:ImageSourceConverter x:Key="ImageSourceConverterKey" /> </ContentPage.Resources> <CollectionView x:Name="collectionView"> <CollectionView.ItemsLayout> <GridItemsLayout Orientation="Horizontal" Span="4" /> </CollectionView.ItemsLayout> <CollectionView.ItemTemplate> <DataTemplate> <Grid Padding="10" RowDefinitions="Auto" ColumnDefinitions="Auto,10,*"> <Image Grid.Column="0" WidthRequest="60" HeightRequest="60" Aspect="AspectFill" Source="{Binding ImageURL, Converter={StaticResource ImageSourceConverterKey}}" /> <StackLayout Grid.Column="2"> <Label FontAttributes="Bold" FontSize="16" Text="{Binding Name}" /> <Label VerticalOptions="End" FontAttributes="Italic" Text="{Binding Location}" /> </StackLayout> </Grid> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </ContentPage> |
▶
더 읽기
■ GridItemsLayout 엘리먼트의 Orientation/Span 속성을 사용해 수직 그리드 레이아웃을 설정하는 방법을 보여준다. ▶ Monkey.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 Monkey { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion #region 위치 - Location /// <summary> /// 위치 /// </summary> public string Location { get; set; } #endregion #region 이미지 URL - ImageURL /// <summary> /// 이미지 URL /// </summary> public string ImageURL { get; set; } #endregion } |
▶ ImageSourceConverter.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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
using System.Globalization; namespace TestProject; /// <summary> /// 이미지 URL→이미지 소스 변환자 /// </summary> public class ImageSourceConverter : IValueConverter { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 변환하기 - Convert(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>변환 값</returns> public object Convert(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { string imageURL = sourceValue as string; if(string.IsNullOrWhiteSpace(imageURL)) { return null; } return ImageSource.FromUri(new Uri(imageURL)); } #endregion #region 역변환하기 - ConvertBack(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 역변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>역변환 값</returns> public object ConvertBack(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { throw new NotImplementedException(); } #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
|
<?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:ImageSourceConverter x:Key="ImageSourceConverterKey" /> </ContentPage.Resources> <CollectionView x:Name="collectionView"> <CollectionView.ItemsLayout> <GridItemsLayout Orientation="Vertical" Span="2" /> </CollectionView.ItemsLayout> <CollectionView.ItemTemplate> <DataTemplate> <Grid Padding="10" RowDefinitions="Auto" ColumnDefinitions="Auto,10,*"> <Image Grid.Column="0" WidthRequest="60" HeightRequest="60" Aspect="AspectFill" Source="{Binding ImageURL, Converter={StaticResource ImageSourceConverterKey}}" /> <StackLayout Grid.Column="2"> <Label FontAttributes="Bold" FontSize="16" Text="{Binding Name}" /> <Label VerticalOptions="End" FontAttributes="Italic" Text="{Binding Location}" /> </StackLayout> </Grid> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </ContentPage> |
▶
더 읽기
■ LinearItemsLayout 엘리먼트의 Orientation 속성을 사용해 CollectionView 객체의 수평 레이아웃을 설정하는 방법을 보여준다. ▶ Monkey.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 Monkey { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion #region 위치 - Location /// <summary> /// 위치 /// </summary> public string Location { get; set; } #endregion #region 이미지 URL - ImageURL /// <summary> /// 이미지 URL /// </summary> public string ImageURL { get; set; } #endregion } |
▶ ImageSourceConverter.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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
using System.Globalization; namespace TestProject; /// <summary> /// 이미지 URL→이미지 소스 변환자 /// </summary> public class ImageSourceConverter : IValueConverter { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 변환하기 - Convert(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>변환 값</returns> public object Convert(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { string imageURL = sourceValue as string; if(string.IsNullOrWhiteSpace(imageURL)) { return null; } return ImageSource.FromUri(new Uri(imageURL)); } #endregion #region 역변환하기 - ConvertBack(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 역변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>역변환 값</returns> public object ConvertBack(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { throw new NotImplementedException(); } #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
|
<?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:ImageSourceConverter x:Key="ImageSourceConverterKey" /> </ContentPage.Resources> <CollectionView x:Name="collectionView"> <CollectionView.ItemsLayout> <LinearItemsLayout Orientation="Horizontal" /> </CollectionView.ItemsLayout> <CollectionView.ItemTemplate> <DataTemplate> <Grid Padding="10" RowDefinitions="Auto" ColumnDefinitions="Auto,10,*"> <Image Grid.Column="0" WidthRequest="60" HeightRequest="60" Aspect="AspectFill" Source="{Binding ImageURL, Converter={StaticResource ImageSourceConverterKey}}" /> <StackLayout Grid.Column="2"> <Label FontAttributes="Bold" FontSize="16" Text="{Binding Name}" /> <Label VerticalOptions="End" FontAttributes="Italic" Text="{Binding Location}" /> </StackLayout> </Grid> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </ContentPage> |
더 읽기
■ LinearItemsLayout 엘리먼트의 Orientation 속성을 사용해 CollectionView 객체의 수직 레이아웃을 설정하는 방법을 보여준다. ▶ Monkey.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 Monkey { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion #region 위치 - Location /// <summary> /// 위치 /// </summary> public string Location { get; set; } #endregion #region 이미지 URL - ImageURL /// <summary> /// 이미지 URL /// </summary> public string ImageURL { get; set; } #endregion } |
▶ ImageSourceConverter.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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
using System.Globalization; namespace TestProject; /// <summary> /// 이미지 URL→이미지 소스 변환자 /// </summary> public class ImageSourceConverter : IValueConverter { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 변환하기 - Convert(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>변환 값</returns> public object Convert(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { string imageURL = sourceValue as string; if(string.IsNullOrWhiteSpace(imageURL)) { return null; } return ImageSource.FromUri(new Uri(imageURL)); } #endregion #region 역변환하기 - ConvertBack(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 역변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>역변환 값</returns> public object ConvertBack(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { throw new NotImplementedException(); } #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
|
<?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:ImageSourceConverter x:Key="ImageSourceConverterKey" /> </ContentPage.Resources> <CollectionView x:Name="collectionView"> <CollectionView.ItemsLayout> <LinearItemsLayout Orientation="Vertical" /> </CollectionView.ItemsLayout> <CollectionView.ItemTemplate> <DataTemplate> <Grid Padding="10" RowDefinitions="Auto" ColumnDefinitions="Auto,10,*"> <Image Grid.Column="0" WidthRequest="60" HeightRequest="60" Aspect="AspectFill" Source="{Binding ImageURL, Converter={StaticResource ImageSourceConverterKey}}" /> <StackLayout Grid.Column="2"> <Label FontAttributes="Bold" FontSize="16" Text="{Binding Name}" /> <Label VerticalOptions="End" FontAttributes="Italic" Text="{Binding Location}" /> </StackLayout> </Grid> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </ContentPage> |
더 읽기
■ LinearItemsLayout 엘리먼트의 SnapPointsType/SnapPointsAlignment 속성을 사용해 CarouselView 객체의 스냅을 설정하는 방법을 보여준다. ▶ PhotoModel.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 PhotoModel { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get; set; } #endregion #region 제목 - Title /// <summary> /// 제목 /// </summary> public string Title { get; set; } #endregion #region 이미지 소스 - ImageSource /// <summary> /// 이미지 소스 /// </summary> public ImageSource ImageSource { 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 50 51 52 53
|
<?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"> <Grid Margin="10" RowDefinitions="*,2*,*"> <CarouselView x:Name="carouselView" Grid.Row="1" BackgroundColor="Cornsilk" PeekAreaInsets="100"> <CarouselView.ItemsLayout> <LinearItemsLayout Orientation="Horizontal" ItemSpacing="10" SnapPointsType="MandatorySingle" SnapPointsAlignment="Start" /> </CarouselView.ItemsLayout> <CarouselView.ItemTemplate> <DataTemplate> <Grid> <Frame HorizontalOptions="Center" WidthRequest="150" HeightRequest="200" CornerRadius="5" BorderColor="DarkGray" HasShadow="True"> <StackLayout Spacing="10"> <Label HorizontalOptions="Center" FontSize="16" Text="{Binding ID}" /> <Label HorizontalOptions="Center" FontSize="18" FontAttributes="Bold" Text="{Binding Title}" /> <Image HorizontalOptions="Center" WidthRequest="200" HeightRequest="200" Aspect="Fill" Source="{Binding ImageSource}" /> </StackLayout> </Frame> </Grid> </DataTemplate> </CarouselView.ItemTemplate> </CarouselView> </Grid> </ContentPage> |
▶ MainPage.xaml.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
|
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); List<PhotoModel> list = new List<PhotoModel>(); list.Add(new PhotoModel { ID = "0001", Title = "풍경1", ImageSource = ImageSource.FromFile("sample1.jpg") }); list.Add(new PhotoModel { ID = "0002", Title = "풍경2", ImageSource = ImageSource.FromFile("sample2.jpg") }); list.Add(new PhotoModel { ID = "0003", Title = "풍경3", ImageSource = ImageSource.FromFile("sample3.jpg") }); list.Add(new PhotoModel { ID = "0004", Title = "풍경4", ImageSource = ImageSource.FromFile("sample4.jpg") }); this.carouselView.ItemsSource = list; } #endregion } |
TestProject.zip
■ LinearItemsLayout 엘리먼트의 ItemSpacing 속성을 사용해 CarouselView 객체의 항목 간격을 설정하는 방법을 보여준다. ▶ PhotoModel.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 PhotoModel { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get; set; } #endregion #region 제목 - Title /// <summary> /// 제목 /// </summary> public string Title { get; set; } #endregion #region 이미지 소스 - ImageSource /// <summary> /// 이미지 소스 /// </summary> public ImageSource ImageSource { 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 50
|
<?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"> <Grid Margin="10" RowDefinitions="*,2*,*"> <CarouselView x:Name="carouselView" Grid.Row="1" BackgroundColor="Cornsilk" PeekAreaInsets="200"> <CarouselView.ItemsLayout> <LinearItemsLayout Orientation="Horizontal" ItemSpacing="10" /> </CarouselView.ItemsLayout> <CarouselView.ItemTemplate> <DataTemplate> <Grid> <Frame HorizontalOptions="Center" HeightRequest="300" CornerRadius="5" BorderColor="DarkGray" HasShadow="True"> <StackLayout Spacing="10"> <Label HorizontalOptions="Center" FontSize="16" Text="{Binding ID}" /> <Label HorizontalOptions="Center" FontSize="18" FontAttributes="Bold" Text="{Binding Title}" /> <Image HorizontalOptions="Center" WidthRequest="200" HeightRequest="200" Aspect="Fill" Source="{Binding ImageSource}" /> </StackLayout> </Frame> </Grid> </DataTemplate> </CarouselView.ItemTemplate> </CarouselView> </Grid> </ContentPage> |
▶ MainPage.xaml.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
|
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); List<PhotoModel> list = new List<PhotoModel>(); list.Add(new PhotoModel { ID = "0001", Title = "풍경1", ImageSource = ImageSource.FromFile("sample1.jpg") }); list.Add(new PhotoModel { ID = "0002", Title = "풍경2", ImageSource = ImageSource.FromFile("sample2.jpg") }); list.Add(new PhotoModel { ID = "0003", Title = "풍경3", ImageSource = ImageSource.FromFile("sample3.jpg") }); list.Add(new PhotoModel { ID = "0004", Title = "풍경4", ImageSource = ImageSource.FromFile("sample4.jpg") }); this.carouselView.ItemsSource = list; } #endregion } |
더 읽기
■ LinearItemsLayout 엘리먼트의 Orientation 속성을 사용해 CarouselView 객체의 수직 레이아웃을 설정하는 방법을 보여준다. ▶ PhotoModel.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 PhotoModel { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public string ID { get; set; } #endregion #region 제목 - Title /// <summary> /// 제목 /// </summary> public string Title { get; set; } #endregion #region 이미지 소스 - ImageSource /// <summary> /// 이미지 소스 /// </summary> public ImageSource ImageSource { 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
|
<?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"> <Grid Margin="10" RowDefinitions="*,2*,*"> <CarouselView x:Name="carouselView" Grid.Row="1" BackgroundColor="Cornsilk"> <CarouselView.ItemsLayout> <LinearItemsLayout Orientation="Vertical" /> </CarouselView.ItemsLayout> <CarouselView.ItemTemplate> <DataTemplate> <Grid> <Frame HorizontalOptions="Center" HeightRequest="300" CornerRadius="5" BorderColor="DarkGray" HasShadow="True"> <StackLayout Spacing="10"> <Label HorizontalOptions="Center" FontSize="16" Text="{Binding ID}" /> <Label HorizontalOptions="Center" FontSize="18" FontAttributes="Bold" Text="{Binding Title}" /> <Image HorizontalOptions="Center" WidthRequest="200" HeightRequest="200" Aspect="Fill" Source="{Binding ImageSource}" /> </StackLayout> </Frame> </Grid> </DataTemplate> </CarouselView.ItemTemplate> </CarouselView> </Grid> </ContentPage> |
▶ MainPage.xaml.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
|
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); List<PhotoModel> list = new List<PhotoModel>(); list.Add(new PhotoModel { ID = "0001", Title = "풍경1", ImageSource = ImageSource.FromFile("sample1.jpg") }); list.Add(new PhotoModel { ID = "0002", Title = "풍경2", ImageSource = ImageSource.FromFile("sample2.jpg") }); list.Add(new PhotoModel { ID = "0003", Title = "풍경3", ImageSource = ImageSource.FromFile("sample3.jpg") }); list.Add(new PhotoModel { ID = "0004", Title = "풍경4", ImageSource = ImageSource.FromFile("sample4.jpg") }); this.carouselView.ItemsSource = list; } #endregion } |
더 읽기
■ StackLayout 엘리먼트에서 BindableLayout.ItemsSource 첨부 속성을 사용하는 방법을 보여준다. ▶ FontModel.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
|
namespace TestProject; /// <summary> /// 폰트 모델 /// </summary> public class FontModel { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 아이콘 - Icon /// <summary> /// 아이콘 /// </summary> public ImageSource Icon { get; set; } #endregion #region 글리프 - Glyph /// <summary> /// 글리프 /// </summary> public string Glyph { get; set; } #endregion } |
▶ FontCollection.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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
using System.Globalization; using System.Text.RegularExpressions; namespace TestProject { /// <summary> /// 폰트 컬렉션 /// </summary> public class FontCollection : List<FontModel> { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - FontCollection() /// <summary> /// 생성자 /// </summary> public FontCollection() { for(int i = 0xf0ff ; i < 0xf3aa; i++) { string escapedUnicode = "\\u" + i.ToString("x4"); string nonEscapedUnicode = GetNonEscapedUnicodeString(escapedUnicode); FontImageSource fontImageSource = new FontImageSource(); fontImageSource.Color = Colors.Blue; fontImageSource.FontFamily = "ionicons"; fontImageSource.Glyph = nonEscapedUnicode; Add(new FontModel { Icon = fontImageSource, Glyph = escapedUnicode }); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 비 이스케이프 유니코드 문자열 구하기 - GetNonEscapedUnicodeString(sourceEscapedUnicodeString) /// <summary> /// 비 이스케이프 유니코드 문자열 구하기 /// </summary> /// <param name="sourceEscapedUnicodeString">소스 이스케이프 유니코드 문자열</param> /// <returns>비 이스케이프 유니코드 문자열</returns> private string GetNonEscapedUnicodeString(string sourceEscapedUnicodeString) { return Regex.Replace ( sourceEscapedUnicodeString, @"\\u(?<Value>[a-zA-Z0-9]{4})", m => { return ((char)int.Parse(m.Groups["Value"].Value, NumberStyles.HexNumber)).ToString(); } ); } #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
|
<?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:FontCollection x:Key="FontCollectionKey" /> </ContentPage.Resources> <ScrollView Margin="20"> <StackLayout BindableLayout.ItemsSource="{StaticResource FontCollectionKey}"> <BindableLayout.ItemTemplate> <DataTemplate> <StackLayout Orientation="Horizontal"> <Image VerticalOptions="Center" WidthRequest="32" HeightRequest="32" Source="{Binding Icon}" /> <Label Margin="10,0,0,0" VerticalOptions="Center" Text="{Binding Glyph}" /> </StackLayout> </DataTemplate> </BindableLayout.ItemTemplate> </StackLayout> </ScrollView> </ContentPage> |
TestProject.zip
■ VerticalStackLayout 엘리먼트의 Spacing 속성을 사용하는 방법을 보여준다. ▶ 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
|
<?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"> <VerticalStackLayout HorizontalOptions="Center" VerticalOptions="Center" Spacing="10"> <Label Text="Primary colors" /> <Rectangle WidthRequest="300" HeightRequest="30" Fill="Red" /> <Rectangle WidthRequest="300" HeightRequest="30" Fill="Yellow" /> <Rectangle WidthRequest="300" HeightRequest="30" Fill="Blue" /> <Label Text="Secondary colors" /> <Rectangle WidthRequest="300" HeightRequest="30" Fill="Green" /> <Rectangle WidthRequest="300" HeightRequest="30" Fill="Orange" /> <Rectangle WidthRequest="300" HeightRequest="30" Fill="Purple" /> </VerticalStackLayout> </ContentPage> |
TestProject.zip
■ HorizontalStackLayout 엘리먼트의 Spacing 속성을 사용하는 방법을 보여준다. ▶ 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
|
<?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"> <HorizontalStackLayout HorizontalOptions="Center" VerticalOptions="Center" Spacing="6"> <Label Text="주 색상" /> <VerticalStackLayout Spacing="6"> <Rectangle WidthRequest="30" HeightRequest="30" Fill="Red" /> <Rectangle WidthRequest="30" HeightRequest="30" Fill="Yellow" /> <Rectangle WidthRequest="30" HeightRequest="30" Fill="Blue" /> </VerticalStackLayout> <Label Text="보조 색상" /> <VerticalStackLayout Spacing="6"> <Rectangle WidthRequest="30" HeightRequest="30" Fill="Green" /> <Rectangle WidthRequest="30" HeightRequest="30" Fill="Orange" /> <Rectangle WidthRequest="30" HeightRequest="30" Fill="Purple" /> </VerticalStackLayout> </HorizontalStackLayout> </ContentPage> |
TestProject.zip
■ Grid 엘리먼트에서 중첩 그리드를 사용하는 방법을 보여준다. ▶ DoubleToStringConverter.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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
using System.Globalization; namespace Testproject; /// <summary> /// 실수→문자열 변환자 /// </summary> public class DoubleToStringConverter : IValueConverter { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 변환하기 - Convert(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>변환 값</returns> public object Convert(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { if(int.TryParse((string)parameter, out int decimalPoint)) { return ((double)sourceValue).ToString($"f{decimalPoint}"); } else { return ((double)sourceValue).ToString(); } } #endregion #region 역변환하기 - ConvertBack(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 역변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>역변환 값</returns> public object ConvertBack(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { throw new NotImplementedException(); } #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
|
<?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:DoubleToStringConverter x:Key="DoubleToStringConverterKey" /> <Style TargetType="Label"> <Setter Property="HorizontalTextAlignment" Value="Center" /> </Style> </ContentPage.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height="500" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <BoxView x:Name="boxView" Color="Black" /> <Grid Grid.Row="1" Margin="20" RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto"> <Slider x:Name="redSlider" /> <Label Grid.Row="1" Text="{Binding Source={x:Reference redSlider}, Path=Value, ConverterParameter=2, Converter={StaticResource DoubleToStringConverterKey}, StringFormat='적색 : {0}'}" /> <Slider x:Name="greenSlider" Grid.Row="2" /> <Label Grid.Row="3" Text="{Binding Source={x:Reference greenSlider}, Path=Value, ConverterParameter=2, Converter={StaticResource DoubleToStringConverterKey}, StringFormat='녹색 : {0}'}" /> <Slider x:Name="blueSlider" Grid.Row="4" /> <Label Grid.Row="5" Text="{Binding Source={x:Reference blueSlider}, Path=Value, ConverterParameter=2, Converter={StaticResource DoubleToStringConverterKey}, StringFormat='청색 : {0}'}" /> </Grid> </Grid> </ContentPage> |
▶ MainPage.xaml.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 38 39 40 41 42 43 44 45
|
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); this.redSlider.ValueChanged += slider_ValueChanged; this.greenSlider.ValueChanged += slider_ValueChanged; this.blueSlider.ValueChanged += slider_ValueChanged; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 슬라이더 값 변경시 처리하기 - slider_ValueChanged(sender, e) /// <summary> /// 슬라이더 값 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void slider_ValueChanged(object sender, ValueChangedEventArgs e) { this.boxView.Color = Color.FromRgb(this.redSlider.Value, this.greenSlider.Value, this.blueSlider.Value); } #endregion } |
TestProject.zip
■ FlexLayout 엘리먼트의 Grow/Order/Basis 첨부 속성을 사용하는 방법을 보여준다. ▶ 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
|
<?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"> <FlexLayout Direction="Column"> <!-- 머리말 --> <Label BackgroundColor="Orange" HorizontalTextAlignment="Center" FontSize="18" Text="HEADER" /> <!-- 본문 --> <FlexLayout FlexLayout.Grow="1"> <!-- 내용 --> <Label FlexLayout.Grow="1" BackgroundColor="White" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" FontSize="18" Text="CONTENT" /> <!-- 탐색 항목 --> <BoxView FlexLayout.Basis="50" FlexLayout.Order="-1" Color="Blue" /> <!-- 부가 항목 --> <BoxView FlexLayout.Basis="50" Color="Yellow" /> </FlexLayout> <!-- 꼬리말 --> <Label BackgroundColor="Red" HorizontalTextAlignment="Center" FontSize="18" Text="FOOTER" /> </FlexLayout> </ContentPage> |
TestProject.zip
■ FlexLayout 엘리먼트의 Direction/AlignItems/JustifyContent 속성을 사용해 항목을 나열하는 방법을 보여준다. ▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
<?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"> <FlexLayout Direction="Column" AlignItems="Center" JustifyContent="SpaceEvenly"> <Label FontSize="18" Text="FlexLayout in Action" /> <Image HeightRequest="300" Source="dotnet_bot.png" /> <Button Text="Do-Nothing Button" /> <Label Text="Another Label" /> </FlexLayout> </ContentPage> |
TestProject.zip
■ HorizontalStackLayout 엘리먼트를 사용하는 방법을 보여준다. ▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
<?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"> <HorizontalStackLayout HorizontalOptions="Center" VerticalOptions="Center"> <Rectangle VerticalOptions="Center" WidthRequest="30" HeightRequest="30" Fill="Red" /> <Label Margin="10,0,0,0" VerticalOptions="Center" FontSize="18" Text="Red" /> </HorizontalStackLayout> </ContentPage> |
TestProject.zip
■ AbsoluteLayout 클래스의 SetLayoutFlags/SetLayoutBounds 정적 메소드를 사용하는 방법을 보여준다. ▶ MainPage.xaml
|
<?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"> </ContentPage> |
▶ MainPage.xaml.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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
using Microsoft.Maui.Layouts; namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); BoxView boxView1 = new BoxView { Color = Colors.Blue }; AbsoluteLayout.SetLayoutFlags (boxView1, AbsoluteLayoutFlags.PositionProportional); AbsoluteLayout.SetLayoutBounds(boxView1, new Rect(0.5, 0, 100, 25)); BoxView boxView2 = new BoxView { Color = Colors.Green }; AbsoluteLayout.SetLayoutFlags (boxView2, AbsoluteLayoutFlags.PositionProportional); AbsoluteLayout.SetLayoutBounds(boxView2, new Rect(0, 0.5, 25, 100)); BoxView boxView3 = new BoxView { Color = Colors.Red }; AbsoluteLayout.SetLayoutFlags (boxView3, AbsoluteLayoutFlags.PositionProportional); AbsoluteLayout.SetLayoutBounds(boxView3, new Rect(1, 0.5, 25, 100)); BoxView boxView4 = new BoxView { Color = Colors.Black }; AbsoluteLayout.SetLayoutFlags (boxView4, AbsoluteLayoutFlags.PositionProportional); AbsoluteLayout.SetLayoutBounds(boxView4, new Rect(0.5, 1, 100, 25)); Label label = new Label { Text = "Centered text" }; AbsoluteLayout.SetLayoutFlags (label, AbsoluteLayoutFlags.PositionProportional); AbsoluteLayout.SetLayoutBounds(label, new Rect(0.5, 0.5, 110, 25)); Content = new AbsoluteLayout { Children = { boxView1, boxView2, boxView3, boxView4, label } }; } #endregion } |
TestProject.zip
■ AbsoluteLayout 엘리먼트의 LayoutFlags/LayoutBounds 첨부 속성을 사용하는 방법을 보여준다. ▶ 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
|
<?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"> <AbsoluteLayout> <BoxView AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds="0.5,0,100,25" Color="Blue" /> <BoxView AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds="0,0.5,25,100" Color="Green" /> <BoxView AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds="1,0.5,25,100" Color="Red" /> <BoxView AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds="0.5,1,100,25" Color="Black" /> <Label AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds="0.5,0.5,110,25" Text="Centered text" /> </AbsoluteLayout> </ContentPage> |
TestProject.zip
■ AbsoluteLayout 클래스의 SetLayoutBounds 정적 메소드를 사용하는 방법을 보여준다. ▶ MainPage.xaml
|
<?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"> </ContentPage> |
▶ MainPage.xaml.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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
namespace TestProject; /// <summary> /// 메인 페이지 /// </summary> public partial class MainPage : ContentPage { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainPage() /// <summary> /// 생성자 /// </summary> public MainPage() { InitializeComponent(); AbsoluteLayout absoluteLayout = new AbsoluteLayout { Margin = new Thickness(20) }; BoxView boxView1 = new BoxView { Color = Colors.Silver }; absoluteLayout.Add(boxView1); AbsoluteLayout.SetLayoutBounds(boxView1, new Rect(0, 10, 200, 5)); BoxView boxView2 = new BoxView { Color = Colors.Silver }; absoluteLayout.Add(boxView2); AbsoluteLayout.SetLayoutBounds(boxView2, new Rect(0, 20, 200, 5)); BoxView boxView3 = new BoxView { Color = Colors.Silver }; absoluteLayout.Add(boxView3); AbsoluteLayout.SetLayoutBounds(boxView3, new Rect(10, 0, 5, 65)); BoxView boxView4 = new BoxView { Color = Colors.Silver }; absoluteLayout.Add(boxView4); AbsoluteLayout.SetLayoutBounds(boxView4, new Rect(20, 0, 5, 65)); Label label = new Label { Text = "Stylish Header", FontSize = 24 }; absoluteLayout.Add(label); AbsoluteLayout.SetLayoutBounds(label, new Rect(30, 25, 200, 30)); Content = absoluteLayout; } #endregion } |
TestProject.zip
■ AbsoluteLayout 엘리먼트의 LayoutBounds 첨부 속성을 사용하는 방법을 보여준다. ▶ 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
|
<?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"> <AbsoluteLayout Margin="20"> <BoxView AbsoluteLayout.LayoutBounds="0,10,200,5" Color="Silver" /> <BoxView AbsoluteLayout.LayoutBounds="0,20,200,5" Color="Silver" /> <BoxView AbsoluteLayout.LayoutBounds="10,0,5,65" Color="Silver" /> <BoxView AbsoluteLayout.LayoutBounds="20,0,5,65" Color="Silver" /> <Label AbsoluteLayout.LayoutBounds="30,25" Text="Stylish Header" FontSize="24" /> </AbsoluteLayout> </ContentPage> |
TestProject.zip
■ 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> |
TestProject.zip
■ AbsoluteLayout 엘리먼트를 사용하는 방법을 보여준다. ▶ 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
|
<?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"> <AbsoluteLayout HorizontalOptions="Center" VerticalOptions="Center"> <BoxView AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds="0.5,0,100,100" Rotation="30" Color="Red" /> <BoxView AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds="0.5,0,100,100" Rotation="60" Color="Green" /> <BoxView AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds="0.5,0,100,100" Color="Blue" /> </AbsoluteLayout> </ContentPage> |
TestProject.zip
■ FlexLayout 엘리먼트를 사용하는 방법을 보여준다. ▶ MainPage.xaml
|
<?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"> <FlexLayout Direction="Column" AlignItems="Center" JustifyContent="SpaceEvenly"> <Label Text="FlexLayout in Action" /> <Button Text="Button" /> <Label Text="Another Label" /> </FlexLayout> </ContentPage> |
TestProject.zip
■ VerticalStackLayout 엘리먼트를 사용하는 방법을 보여준다. ▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
<?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"> <VerticalStackLayout HorizontalOptions="Center" VerticalOptions="Center" Margin="10,10,10,10"> <Label Text="The VericalStackLayout has its Margin property set, to control the rendering position of the VerticalStackLayout." /> <Label Margin="0,10,0,0" Text="The Padding property can be set to specify the distance between the VerticalStackLayout and its children." /> <Label Margin="0,10,0,0" Text="The Spacing property can be set to specify the distance between views in the VerticalStackLayout." /> </VerticalStackLayout> </ContentPage> |
TestProject.zip