2017-10-27 10 views
0

私はxamarinフォームにクロスプラットフォームのアプリをカルーセルビューを追加しようとしています:Xamarinは空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:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView" 
    x:Class="test.Pagina3"> 


    <ContentPage.Content> 
     <StackLayout HorizontalOptions="Center" VerticalOptions="Center" WidthRequest="300" 
      HeightRequest="190"> 
      <cv:CarouselView x:Name="carosello" BackgroundColor="Yellow"> 
       <cv:CarouselView.ItemTemplate> 

        <DataTemplate> 

         <StackLayout HorizontalOptions="Center" VerticalOptions="Center"> 

          <Label x:Name = "label_nome" 
           Text = "{Binding nome}" 
           TextColor = "Black" /> 

         </StackLayout> 
        </DataTemplate> 

       </cv:CarouselView.ItemTemplate> 
      </cv:CarouselView> 
     </StackLayout> 
    </ContentPage.Content> 
</ContentPage> 

とは、私の見解モデルのコードです Xamarin CarouselView Not Displayed

using System; 
using System.Collections.Generic; 
using System.Collections.ObjectModel; 

using Xamarin.Forms; 

namespace test 
{ 
    public partial class Pagina3 : ContentPage 
    { 
     public Pagina3() 
     { 
      InitializeComponent(); 

      //ViewModelSpesa spesa = new ViewModelSpesa(); 
      List<Oggetto_spesa> list = new List<Oggetto_spesa>(); 

      list.Add(new Oggetto_spesa("jsna", 123.1, "13sd")); 
      carosello.ItemsSource = list; 
     } 

    } 
} 

結果が空黄色の図であり、私はこのような他の質問を見てきました

運がない、何が間違っているのですか?そう、これが完了としてマークすることができます答えとして

+0

- :ここで

は私のビューモデルコードです} =新しいリスト(); また、あなたのリストには現在のところ1つのアイテムしか追加していないので、表示するには1つだけ表示されます。 –

+0

は "; expected"というエラーになりました。テスト... –

+0

申し訳ありませんが、あなたはコンストラクタの外に宣言し、それを公開する必要があります –

答えて

0

追加コメント:

あなたカルーセルビューのコードは結構ですが、バインディングは、パブリックとしてマークする必要があります。

変更

List<Oggetto_spesa> list = new List<Oggetto_spesa>(); 

public List<Sensors> list { get; } = new List<Sensors>(); 

とコンストラクタの外に移動してくださいします。

また、 "Oggetto_spesa"クラスでは、 "label_nome"がpublicであることを確認してください。ただ、今後の参考のため

、あなたがカルーセルビューの詳細のいずれかを更新したい(と私はあなたがバインディングを使用しているので、あなたが行うと仮定)場合、あなたはのObservableCollection ObservableCollection<> vs. List<>

1
Here is my Xaml code:- 

<?xml version="1.0" encoding="UTF-8"?> 
<ContentPage 
     xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     x:Class="MyCairns.Views.ZoomReportImage" 
     xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView" 
      x:Name="ZoomPage" xmlns:local="clr-namespace:MyCairns" 
     Title="{local:Copy ViewPhoto}" > 
    <StackLayout x:Name="stackcarosel" > 
     <cv:CarouselView x:Name="CarouselZoos" ItemsSource="{Binding ImagesZoom}" > 
      <cv:CarouselView.ItemTemplate> 
       <DataTemplate> 
        <Grid> 
         <Grid.RowDefinitions> 
          <RowDefinition Height="*"/> 
         </Grid.RowDefinitions> 
         <Image Source="{Binding Source}" />      
        </Grid> 
       </DataTemplate> 
      </cv:CarouselView.ItemTemplate> 
     </cv:CarouselView> 
    </StackLayout> 

</ContentPage> 

にリストを変更する必要がありますここに私のXaml.csコード: -

ObservableCollection<GalleryImage> _images = new ObservableCollection<GalleryImage>(); 

_images .Add(新GalleryImage( "jsna"、123.1、 "13SD"));

PageViewModel =新しいPageViewModel(_images); ; {取得一覧 リスト:あなたはそれを「取得」することができますを確認する必要があります動作するようにあなたのリストとの結合について

ObservableCollection<GalleryImage> _images = new ObservableCollection<GalleryImage>(); 


    public ObservableCollection<GalleryImage> ImagesZoom{get => _images;} 

    public PageViewModel(ObservableCollection<GalleryImage> _images) 
    { 
     this._images = _images; 
    } 
関連する問題