0
我使用Xamarin Forms v2.3.1.114,我想在我的應用程序中創建一個調查頁面。Xamarin Forms Carousel查看丟失的選定值(Survey Sample)
我的基本類是這樣的:
public class Question
{
public string Title { get; set; }
public List<string> Answers { get; set; }
}
我的示例代碼是這樣的:
ObservableCollection<Question> Questions = new ObservableCollection<Question>();
Questions.Add (
new Question() {
Title = "Question A",
Answers = new List<string>{
"Answer A",
"Answer B",
"Answer C",
"Answer D"
}
}
);
Questions.Add (
new Question() {
Title = "Question B",
Answers = new List<string>{
"Answer A",
"Answer B",
"Answer C",
"Answer D",
"Answer E",
"Answer F"
}
}
);
我的XAML是以下幾點:
<Grid Grid.Row="1">
<cv:CarouselView x:Name="CarouselQuestions">
<cv:CarouselView.ItemTemplate>
<DataTemplate>
<Grid Padding="12">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" BackgroundColor="#404040">
<ContentView Padding="12">
<Label TextColor="White" HorizontalOptions="Start" Text="{Binding Title}"/>
</ContentView>
</Grid>
<ListView Grid.Row="1" ItemsSource="{Binding Answers}" BackgroundColor="Transparent" HasUnevenRows="true">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="12">
<Label TextColor="Black" Text="{Binding}"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</DataTemplate>
</cv:CarouselView.ItemTemplate>
</cv:CarouselView>
</Grid>
我用卡羅uselView控件從Nuget中,但是當我從一個列表視圖中選擇一個值並滑動輪播時,所選值已丟失。
我該如何解決這個問題?
謝謝!
你做你的'的ObservableCollection Questions'全局或局部剛? –