첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
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
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요