■現状
現在Xamarin.FormsでiPhoneアプリを作成しております。
その際に、CarouselViewを用いた画面を作成したいと思っていますが
うまくデータが表示されません。
ネット上にある動画やサンプルコードを転写したのですが、
うまく動作しないため、知恵をお貸し頂けないかと思い投稿いたしました。
■やりたい事
画面にコードビハインドで定義したリストを
カルーセルビューを用いて表示したいです。
下記に自分の環境と実際に試したソースコードを貼りますので、
何か間違いがあればご指摘いただけると幸いです。
■環境周り
・開発環境 : VisualStudio For Mac
・開発環境 : Xamarin.Forms (PCLを利用しています)
・使用しているプラグインXamarin.Forms.CarouselView
■XAML
<?xml version="1.0" encoding="utf-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:control="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView" xmlns:local="clr-namespace:carouselTrial" x:Class="carouselTrial.carouselTrialPage"> <StackLayout x:Name="stackPrinc" Orientation="Vertical"> <Label Text="SAMPLE HEAD" /> <control:CarouselView x:Name="car" VerticalOptions="Start" HeightRequest="200" BackgroundColor="Aqua"> <control:CarouselView.ItemTemplate> <DataTemplate> <StackLayout Orientation="Horizontal"> <Button Text="{Binding texto}" /> </StackLayout> </DataTemplate> </control:CarouselView.ItemTemplate> </control:CarouselView> <Label Text="SAMPLE FOOT" /> </StackLayout> </ContentPage>
■コードビハインド
using Xamarin.Forms; using System.Collections.Generic; using System.Reflection; namespace carouselTrial { public partial class carouselTrialPage : ContentPage { public class Dados { public string texto { get; set; } } List<Dados> lista; public carouselTrialPage() { InitializeComponent(); lista = new List<Dados>(); lista.Add(new Dados { texto = "text1", }); lista.Add(new Dados { texto = "text2", }); lista.Add(new Dados { texto = "text3", }); lista.Add(new Dados { texto = "text4", }); car.ItemsSource = lista; } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。