2017-01-30 9 views
0

私はXamarin Forms v2.3.1.114を使用しています。私は自分のアプリで調査ページを作成したいと思います。Xamarinフォームカルーセルビュー選択した値が失われました(アンケートサンプル)

<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> 

survey app

私が使用:

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は以下の通りです:

public class Question 
{ 
    public string Title { get; set; } 
    public List<string> Answers { get; set; } 
} 

私のサンプルコードはこれです:

私の基本的なクラスがこれですカロuselViewコントロールをNugetから取得しますが、1つのリストビューから値を選択してカルーセルをスワイプすると、選択した値が失われています。

どうすればこの問題を解決できますか?

ありがとうございます!

+0

「ObservableCollection 質問」グローバルまたはローカルのみですか? –

答えて

1

カルーセル項目は、あなたが選択した項目を更新する必要がある必要があり、再利用するか、このような何かを追加する必要がありますあなたのCarouselView項目の新しいプロパティにそれを結合されているので:

object _selectedItem; 
public object SelectedItem{ 
    get{ 
     return _selectedItem; 
    } 
    set{ 
     _selectedItem = value; 
     OnPropertyChanged(); 
    } 
} 

をそして、あなたのListViewコントロールにバインドを追加Xaml

<ListView SelectedItem="{Binding SelectedItem}" Grid.Row="1" ItemsSource="{Binding Answers}" BackgroundColor="Transparent" HasUnevenRows="true"> 
関連する問題