728x90
반응형
728x170
■ DataTemplate 클래스를 사용해 CarouselView 클래스의 ItemTemplate 속성을 설정하는 방법을 보여준다.
▶ 예제 코드 (C#)
private CarouselView carouselView;
...
carouselView.ItemTemplate = new DataTemplate
(
() =>
{
#region ID 레이블을 설정한다.
Label idLabel = new Label
{
HorizontalOptions = LayoutOptions.Center,
FontSize = 16
};
idLabel.SetBinding(Label.TextProperty, "ID");
#endregion
#region 제목 레이블을 설정한다.
Label titleLabel = new Label
{
HorizontalOptions = LayoutOptions.Center,
FontSize = 18,
FontAttributes = FontAttributes.Bold
};
titleLabel.SetBinding(Label.TextProperty, "Title");
#endregion
#region 이미지 소스 이미지를 설정한다.
Image imageSourceImage = new Image
{
HorizontalOptions = LayoutOptions.Center,
WidthRequest = 200,
HeightRequest = 200,
Aspect = Aspect.Fill
};
imageSourceImage.SetBinding(Image.SourceProperty, "ImageSource");
#endregion
#region 스택 레이아웃을 설정한다.
StackLayout stackLayout = new StackLayout
{
Spacing = 10
};
stackLayout.Children.Add(idLabel );
stackLayout.Children.Add(titleLabel );
stackLayout.Children.Add(imageSourceImage);
#endregion
#region 프레임을 설정한다.
Frame frame = new Frame
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
HeightRequest = 300,
CornerRadius = 5,
BorderColor = Colors.DarkGray,
HasShadow = true
};
frame.Content = stackLayout;
#endregion
#region 그리드를 설정한다.
Grid grid = new Grid();
grid.Children.Add(frame);
#endregion
return grid;
}
);
728x90
반응형
그리드형(광고전용)
'C# > MAUI' 카테고리의 다른 글
[C#/MAUI/.NET6] Shell 엘리먼트 : 태양 일출/일몰 및 달 위상 정보 조회하기 (0) | 2022.07.09 |
---|---|
[C#/MAUI/.NET6] Connectivity 클래스 : ConnectivityChanged 정적 이벤트를 사용해 네트워크 연결 변경시 처리하기 (0) | 2022.07.05 |
[C#/MAUI/.NET6] IImage 인터페이스 : Save 메소드를 사용해 이미지 저장하기 (0) | 2022.07.04 |
[C#/MAUI/.NET6] ICanvas 인터페이스 : FillCircle 메소드를 사용해 원 칠하기 (0) | 2022.07.03 |
[C#/MAUI/.NET6] ICanvas 인터페이스 : BlendMode 속성을 사용해 혼합 모드 설정하기 (프리뷰 버전 오류) (0) | 2022.07.03 |
[C#/MAUI/.NET6] CarouselView 클래스 : ItemTemplate 속성 사용하기 (0) | 2022.07.01 |
[C#/MAUI/.NET6] IMediaPicker 인터페이스 : PickPhotoAsync 메소드를 사용해 갤러리 사진 구하기 (ANDROID) (0) | 2022.07.01 |
[C#/MAUI/.NET6] ProgressBar 클래스 : ProgressTo 메소드 사용하기 (0) | 2022.07.01 |
[C#/MAUI/.NET6] Button 클래스 : ContentLayout 속성 사용하기 (0) | 2022.06.30 |
[C#/MAUI/.NET6] WebView 클래스 : Source 속성을 사용해 로컬 HTML 표시하기 (0) | 2022.06.30 |
댓글을 달아 주세요