Ich benutze Xamarin Forms v2.3.1.114 und ich möchte eine Umfrage in meiner App erstellen.Xamarin Forms Karussell Ansicht verlorene ausgewählte Werte (Umfrage Beispiel)
Meine grundlegende Klasse ist dies:
public class Question
{
public string Title { get; set; }
public List<string> Answers { get; set; }
}
Mein Beispielcode ist dies:
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"
}
}
);
Meine XAML ist die folgende:
<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>
Ich benutze Caro uselView-Steuerelement von Nuget, aber wenn ich einen Wert aus einer Listview und Swipe-Karussell auswählen, wurden die ausgewählten Werte losted.
Wie kann ich das beheben?
Danke !!
Haben Sie Ihre 'ObservableCollection Fragen global oder nur lokal? –