CarouselView in XamarinForms











up vote
0
down vote

favorite












I'm trying to use the CarouselView in the Xamarin project. But I can’t do it. Here are the installed packages:
enter image description hereenter image description here
Here is the 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"
xmlns:local="clr-namespace:FlowersStore"
xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView"
x:Class="FlowersStore.MainPage">

<StackLayout>

<Grid RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height=".3*"/>
<RowDefinition Height=".7*"/>
</Grid.RowDefinitions>
<cv:CarouselView ItemsSource="{Binding Zoos}" x:Name="CarouselZoos">
<cv:CarouselView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image Grid.RowSpan="2" Aspect="AspectFill" Source="{Binding ImageUrl}"/>
<StackLayout Grid.Row="1" BackgroundColor="#80000000" Padding="12">
<Label TextColor="White" Text="{Binding Name}" FontSize="16" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
</StackLayout>
</Grid>
</DataTemplate>
</cv:CarouselView.ItemTemplate>
</cv:CarouselView>
</Grid>

</StackLayout>




And here is the c # code:



using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Xamarin.Forms;

namespace FlowersStore
{
public class Zoo
{
public string ImageUrl { get; set; }
public string Name { get; set; }
}

public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
LoadDataCatouselView();
}

public void LoadDataCatouselView()
{
ObservableCollection<Zoo> Zoos = new ObservableCollection<Zoo>
{
new Zoo
{
ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/23c1dd13-333a-459e-9e23-c3784e7cb434/2016-06-02_1049.png",
Name = "Woodland Park Zoo"
},
new Zoo
{
ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/6b60d27e-c1ec-4fe6-bebe-7386d545bb62/2016-06-02_1051.png",
Name = "Cleveland Zoo"
},
new Zoo
{
ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/e8179889-8189-4acb-bac5-812611199a03/2016-06-02_1053.png",
Name = "Phoenix Zoo"
}
};
CarouselZoos.ItemsSource = Zoos;
}

}
}


I use Xamarin Live Player for debugging. The log on the mobile phone displays the following message:
[LogEntry: Time=19.11.2018 14:54:54 +03:00, Level=Error, Title=Visualization Error, Message=The given key was not present in the dictionary. (KeyNotFoundException)]



How to fix it? Thanks.



Update 1:
I replaced the code based on your advice. I used your advice. I tried to run the application on:




  1. Androind version: 7.1

  2. Emulator: Genymotion Galaxy S7 7.1.0 API 25


And got this error:
enter image description here



What it? :(










share|improve this question
























  • Did you try in a simulator or a physical device?
    – hashimks
    Nov 19 at 12:23






  • 1




    That's problem with the path, I experimented that in one case, I move the entire project solution to the my local drive C: I think it's problem with the compilation.
    – Ivan-San
    2 days ago










  • @hashimks a physical device.
    – Range
    2 days ago










  • @Ivan-San Yes! Yes - yes - yes! This program running! Very big thanks! You can write it as an answer :)
    – Range
    2 days ago















up vote
0
down vote

favorite












I'm trying to use the CarouselView in the Xamarin project. But I can’t do it. Here are the installed packages:
enter image description hereenter image description here
Here is the 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"
xmlns:local="clr-namespace:FlowersStore"
xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView"
x:Class="FlowersStore.MainPage">

<StackLayout>

<Grid RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height=".3*"/>
<RowDefinition Height=".7*"/>
</Grid.RowDefinitions>
<cv:CarouselView ItemsSource="{Binding Zoos}" x:Name="CarouselZoos">
<cv:CarouselView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image Grid.RowSpan="2" Aspect="AspectFill" Source="{Binding ImageUrl}"/>
<StackLayout Grid.Row="1" BackgroundColor="#80000000" Padding="12">
<Label TextColor="White" Text="{Binding Name}" FontSize="16" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
</StackLayout>
</Grid>
</DataTemplate>
</cv:CarouselView.ItemTemplate>
</cv:CarouselView>
</Grid>

</StackLayout>




And here is the c # code:



using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Xamarin.Forms;

namespace FlowersStore
{
public class Zoo
{
public string ImageUrl { get; set; }
public string Name { get; set; }
}

public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
LoadDataCatouselView();
}

public void LoadDataCatouselView()
{
ObservableCollection<Zoo> Zoos = new ObservableCollection<Zoo>
{
new Zoo
{
ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/23c1dd13-333a-459e-9e23-c3784e7cb434/2016-06-02_1049.png",
Name = "Woodland Park Zoo"
},
new Zoo
{
ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/6b60d27e-c1ec-4fe6-bebe-7386d545bb62/2016-06-02_1051.png",
Name = "Cleveland Zoo"
},
new Zoo
{
ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/e8179889-8189-4acb-bac5-812611199a03/2016-06-02_1053.png",
Name = "Phoenix Zoo"
}
};
CarouselZoos.ItemsSource = Zoos;
}

}
}


I use Xamarin Live Player for debugging. The log on the mobile phone displays the following message:
[LogEntry: Time=19.11.2018 14:54:54 +03:00, Level=Error, Title=Visualization Error, Message=The given key was not present in the dictionary. (KeyNotFoundException)]



How to fix it? Thanks.



Update 1:
I replaced the code based on your advice. I used your advice. I tried to run the application on:




  1. Androind version: 7.1

  2. Emulator: Genymotion Galaxy S7 7.1.0 API 25


And got this error:
enter image description here



What it? :(










share|improve this question
























  • Did you try in a simulator or a physical device?
    – hashimks
    Nov 19 at 12:23






  • 1




    That's problem with the path, I experimented that in one case, I move the entire project solution to the my local drive C: I think it's problem with the compilation.
    – Ivan-San
    2 days ago










  • @hashimks a physical device.
    – Range
    2 days ago










  • @Ivan-San Yes! Yes - yes - yes! This program running! Very big thanks! You can write it as an answer :)
    – Range
    2 days ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to use the CarouselView in the Xamarin project. But I can’t do it. Here are the installed packages:
enter image description hereenter image description here
Here is the 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"
xmlns:local="clr-namespace:FlowersStore"
xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView"
x:Class="FlowersStore.MainPage">

<StackLayout>

<Grid RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height=".3*"/>
<RowDefinition Height=".7*"/>
</Grid.RowDefinitions>
<cv:CarouselView ItemsSource="{Binding Zoos}" x:Name="CarouselZoos">
<cv:CarouselView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image Grid.RowSpan="2" Aspect="AspectFill" Source="{Binding ImageUrl}"/>
<StackLayout Grid.Row="1" BackgroundColor="#80000000" Padding="12">
<Label TextColor="White" Text="{Binding Name}" FontSize="16" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
</StackLayout>
</Grid>
</DataTemplate>
</cv:CarouselView.ItemTemplate>
</cv:CarouselView>
</Grid>

</StackLayout>




And here is the c # code:



using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Xamarin.Forms;

namespace FlowersStore
{
public class Zoo
{
public string ImageUrl { get; set; }
public string Name { get; set; }
}

public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
LoadDataCatouselView();
}

public void LoadDataCatouselView()
{
ObservableCollection<Zoo> Zoos = new ObservableCollection<Zoo>
{
new Zoo
{
ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/23c1dd13-333a-459e-9e23-c3784e7cb434/2016-06-02_1049.png",
Name = "Woodland Park Zoo"
},
new Zoo
{
ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/6b60d27e-c1ec-4fe6-bebe-7386d545bb62/2016-06-02_1051.png",
Name = "Cleveland Zoo"
},
new Zoo
{
ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/e8179889-8189-4acb-bac5-812611199a03/2016-06-02_1053.png",
Name = "Phoenix Zoo"
}
};
CarouselZoos.ItemsSource = Zoos;
}

}
}


I use Xamarin Live Player for debugging. The log on the mobile phone displays the following message:
[LogEntry: Time=19.11.2018 14:54:54 +03:00, Level=Error, Title=Visualization Error, Message=The given key was not present in the dictionary. (KeyNotFoundException)]



How to fix it? Thanks.



Update 1:
I replaced the code based on your advice. I used your advice. I tried to run the application on:




  1. Androind version: 7.1

  2. Emulator: Genymotion Galaxy S7 7.1.0 API 25


And got this error:
enter image description here



What it? :(










share|improve this question















I'm trying to use the CarouselView in the Xamarin project. But I can’t do it. Here are the installed packages:
enter image description hereenter image description here
Here is the 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"
xmlns:local="clr-namespace:FlowersStore"
xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView"
x:Class="FlowersStore.MainPage">

<StackLayout>

<Grid RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height=".3*"/>
<RowDefinition Height=".7*"/>
</Grid.RowDefinitions>
<cv:CarouselView ItemsSource="{Binding Zoos}" x:Name="CarouselZoos">
<cv:CarouselView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image Grid.RowSpan="2" Aspect="AspectFill" Source="{Binding ImageUrl}"/>
<StackLayout Grid.Row="1" BackgroundColor="#80000000" Padding="12">
<Label TextColor="White" Text="{Binding Name}" FontSize="16" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
</StackLayout>
</Grid>
</DataTemplate>
</cv:CarouselView.ItemTemplate>
</cv:CarouselView>
</Grid>

</StackLayout>




And here is the c # code:



using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Xamarin.Forms;

namespace FlowersStore
{
public class Zoo
{
public string ImageUrl { get; set; }
public string Name { get; set; }
}

public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
LoadDataCatouselView();
}

public void LoadDataCatouselView()
{
ObservableCollection<Zoo> Zoos = new ObservableCollection<Zoo>
{
new Zoo
{
ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/23c1dd13-333a-459e-9e23-c3784e7cb434/2016-06-02_1049.png",
Name = "Woodland Park Zoo"
},
new Zoo
{
ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/6b60d27e-c1ec-4fe6-bebe-7386d545bb62/2016-06-02_1051.png",
Name = "Cleveland Zoo"
},
new Zoo
{
ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/e8179889-8189-4acb-bac5-812611199a03/2016-06-02_1053.png",
Name = "Phoenix Zoo"
}
};
CarouselZoos.ItemsSource = Zoos;
}

}
}


I use Xamarin Live Player for debugging. The log on the mobile phone displays the following message:
[LogEntry: Time=19.11.2018 14:54:54 +03:00, Level=Error, Title=Visualization Error, Message=The given key was not present in the dictionary. (KeyNotFoundException)]



How to fix it? Thanks.



Update 1:
I replaced the code based on your advice. I used your advice. I tried to run the application on:




  1. Androind version: 7.1

  2. Emulator: Genymotion Galaxy S7 7.1.0 API 25


And got this error:
enter image description here



What it? :(







c# xaml xamarin.forms carousel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago

























asked Nov 19 at 12:00









Range

1054




1054












  • Did you try in a simulator or a physical device?
    – hashimks
    Nov 19 at 12:23






  • 1




    That's problem with the path, I experimented that in one case, I move the entire project solution to the my local drive C: I think it's problem with the compilation.
    – Ivan-San
    2 days ago










  • @hashimks a physical device.
    – Range
    2 days ago










  • @Ivan-San Yes! Yes - yes - yes! This program running! Very big thanks! You can write it as an answer :)
    – Range
    2 days ago


















  • Did you try in a simulator or a physical device?
    – hashimks
    Nov 19 at 12:23






  • 1




    That's problem with the path, I experimented that in one case, I move the entire project solution to the my local drive C: I think it's problem with the compilation.
    – Ivan-San
    2 days ago










  • @hashimks a physical device.
    – Range
    2 days ago










  • @Ivan-San Yes! Yes - yes - yes! This program running! Very big thanks! You can write it as an answer :)
    – Range
    2 days ago
















Did you try in a simulator or a physical device?
– hashimks
Nov 19 at 12:23




Did you try in a simulator or a physical device?
– hashimks
Nov 19 at 12:23




1




1




That's problem with the path, I experimented that in one case, I move the entire project solution to the my local drive C: I think it's problem with the compilation.
– Ivan-San
2 days ago




That's problem with the path, I experimented that in one case, I move the entire project solution to the my local drive C: I think it's problem with the compilation.
– Ivan-San
2 days ago












@hashimks a physical device.
– Range
2 days ago




@hashimks a physical device.
– Range
2 days ago












@Ivan-San Yes! Yes - yes - yes! This program running! Very big thanks! You can write it as an answer :)
– Range
2 days ago




@Ivan-San Yes! Yes - yes - yes! This program running! Very big thanks! You can write it as an answer :)
– Range
2 days ago












4 Answers
4






active

oldest

votes

















up vote
2
down vote



accepted










The problem is with the long path.
An easy solution is to move the entire project solution to a shorter path like C:



Here's an explanation from microsoft:
Path Too Long Exception






share|improve this answer




























    up vote
    2
    down vote













    In your XAML you have the following line:



    <cv:CarouselView ItemsSource="{Binding Zoos}" x:Name="CarouselZoos">


    This means that the code is looking to bind a property named Zoos to the ItemsSource property of the CarouselView. You will need to create a property of type List<View> and implement the INotifyPropertyChanged structure to update the view. You'll also need to assign the content page's BindingContext to itself (BindingContext = this;).



    You may also find that you cannot simply bind a URL to the Image source, and expect the image to appear.






    share|improve this answer





















    • Problem added in the first post, please see
      – Range
      2 days ago


















    up vote
    1
    down vote













    Add the BindingContext=this; after the InitializeComponent(); or else add CarouselZoos.ItemsSource = Zoos; in OnAppearing() method






    share|improve this answer




























      up vote
      1
      down vote













      Try this

      First add this class, for property binding and implement the INotifyPropertyChanged structure to update the view.



      public class ViewModelBase : INotifyPropertyChanged
      {

      string title = string.Empty;

      /// <summary>
      /// Gets or sets the title.
      /// </summary>
      /// <value>The title.</value>
      public string Title
      {
      get { return title; }
      set { SetProperty(ref title, value); }
      }

      string icon = string.Empty;

      /// <summary>
      /// Gets or sets the icon.
      /// </summary>
      /// <value>The icon.</value>
      public string Icon
      {
      get { return icon; }
      set { SetProperty(ref icon, value); }
      }

      bool isBusy;

      /// <summary>
      /// Gets or sets a value indicating whether this instance is busy.
      /// </summary>
      /// <value><c>true</c> if this instance is busy; otherwise, <c>false</c>.</value>
      public bool IsBusy
      {
      get { return isBusy; }
      set
      {
      SetProperty(ref isBusy, value);
      }
      }


      /// <summary>
      /// Sets the property.
      /// </summary>
      /// <returns><c>true</c>, if property was set, <c>false</c> otherwise.</returns>
      /// <param name="backingStore">Backing store.</param>
      /// <param name="value">Value.</param>
      /// <param name="propertyName">Property name.</param>
      /// <param name="onChanged">On changed.</param>
      /// <typeparam name="T">The 1st type parameter.</typeparam>
      protected bool SetProperty<T>(
      ref T backingStore, T value,
      [CallerMemberName]string propertyName = "",
      Action onChanged = null)
      {
      if (EqualityComparer<T>.Default.Equals(backingStore, value))
      return false;

      backingStore = value;
      onChanged?.Invoke();
      OnPropertyChanged(propertyName);
      return true;
      }

      /// <summary>
      /// Occurs when property changed.
      /// </summary>
      public event PropertyChangedEventHandler PropertyChanged;
      /// <summary>
      /// Raises the property changed event.
      /// </summary>
      /// <param name="propertyName">Property name.</param>
      protected void OnPropertyChanged([CallerMemberName]string propertyName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
      }


      Now when you got the base class for bind properties you can add a view model class for bind the properties and follow the MVVM pattern. I think this is the most property way to manipulate the data.



      public class Zoo
      {
      public string ImageUrl { get; set; }
      public string Name { get; set; }
      }

      public class CarouselViewModel : ViewModelBase
      {
      private ObservableCollection<Zoo> zoos;
      public ObservableCollection<Zoo> Zoos
      {
      get => zoos; set => SetProperty(ref zoos, value);
      }

      public CarouselViewModel()
      {
      zoos = new ObservableCollection<Zoo>
      {
      new Zoo
      {
      ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/23c1dd13-333a-459e-9e23-c3784e7cb434/2016-06-02_1049.png",
      Name = "Woodland Park Zoo"
      },
      new Zoo
      {
      ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/6b60d27e-c1ec-4fe6-bebe-7386d545bb62/2016-06-02_1051.png",
      Name = "Cleveland Zoo"
      },
      new Zoo
      {
      ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/e8179889-8189-4acb-bac5-812611199a03/2016-06-02_1053.png",
      Name = "Phoenix Zoo"
      }
      };
      }
      }
      public partial class MainPage : ContentPage
      {
      public CarouselViewModel viewModel;
      public MainPage()
      {
      InitializeComponent();
      this.BindingContext = viewModel = new CarouselViewModel();
      }
      }





      share|improve this answer





















      • I changed the code as you specified, but the error remains the same: (
        – Range
        Nov 19 at 16:54










      • Maybe it's the Xamarin Live Player, did you try to build on your phone or in the simulator? I try for myself and it works with no errors.
        – Ivan-San
        Nov 19 at 17:03










      • Please, see first post
        – Range
        2 days ago











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374192%2fcarouselview-in-xamarinforms%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      2
      down vote



      accepted










      The problem is with the long path.
      An easy solution is to move the entire project solution to a shorter path like C:



      Here's an explanation from microsoft:
      Path Too Long Exception






      share|improve this answer

























        up vote
        2
        down vote



        accepted










        The problem is with the long path.
        An easy solution is to move the entire project solution to a shorter path like C:



        Here's an explanation from microsoft:
        Path Too Long Exception






        share|improve this answer























          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          The problem is with the long path.
          An easy solution is to move the entire project solution to a shorter path like C:



          Here's an explanation from microsoft:
          Path Too Long Exception






          share|improve this answer












          The problem is with the long path.
          An easy solution is to move the entire project solution to a shorter path like C:



          Here's an explanation from microsoft:
          Path Too Long Exception







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 days ago









          Ivan-San

          31518




          31518
























              up vote
              2
              down vote













              In your XAML you have the following line:



              <cv:CarouselView ItemsSource="{Binding Zoos}" x:Name="CarouselZoos">


              This means that the code is looking to bind a property named Zoos to the ItemsSource property of the CarouselView. You will need to create a property of type List<View> and implement the INotifyPropertyChanged structure to update the view. You'll also need to assign the content page's BindingContext to itself (BindingContext = this;).



              You may also find that you cannot simply bind a URL to the Image source, and expect the image to appear.






              share|improve this answer





















              • Problem added in the first post, please see
                – Range
                2 days ago















              up vote
              2
              down vote













              In your XAML you have the following line:



              <cv:CarouselView ItemsSource="{Binding Zoos}" x:Name="CarouselZoos">


              This means that the code is looking to bind a property named Zoos to the ItemsSource property of the CarouselView. You will need to create a property of type List<View> and implement the INotifyPropertyChanged structure to update the view. You'll also need to assign the content page's BindingContext to itself (BindingContext = this;).



              You may also find that you cannot simply bind a URL to the Image source, and expect the image to appear.






              share|improve this answer





















              • Problem added in the first post, please see
                – Range
                2 days ago













              up vote
              2
              down vote










              up vote
              2
              down vote









              In your XAML you have the following line:



              <cv:CarouselView ItemsSource="{Binding Zoos}" x:Name="CarouselZoos">


              This means that the code is looking to bind a property named Zoos to the ItemsSource property of the CarouselView. You will need to create a property of type List<View> and implement the INotifyPropertyChanged structure to update the view. You'll also need to assign the content page's BindingContext to itself (BindingContext = this;).



              You may also find that you cannot simply bind a URL to the Image source, and expect the image to appear.






              share|improve this answer












              In your XAML you have the following line:



              <cv:CarouselView ItemsSource="{Binding Zoos}" x:Name="CarouselZoos">


              This means that the code is looking to bind a property named Zoos to the ItemsSource property of the CarouselView. You will need to create a property of type List<View> and implement the INotifyPropertyChanged structure to update the view. You'll also need to assign the content page's BindingContext to itself (BindingContext = this;).



              You may also find that you cannot simply bind a URL to the Image source, and expect the image to appear.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 19 at 14:35









              Tom

              618412




              618412












              • Problem added in the first post, please see
                – Range
                2 days ago


















              • Problem added in the first post, please see
                – Range
                2 days ago
















              Problem added in the first post, please see
              – Range
              2 days ago




              Problem added in the first post, please see
              – Range
              2 days ago










              up vote
              1
              down vote













              Add the BindingContext=this; after the InitializeComponent(); or else add CarouselZoos.ItemsSource = Zoos; in OnAppearing() method






              share|improve this answer

























                up vote
                1
                down vote













                Add the BindingContext=this; after the InitializeComponent(); or else add CarouselZoos.ItemsSource = Zoos; in OnAppearing() method






                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  Add the BindingContext=this; after the InitializeComponent(); or else add CarouselZoos.ItemsSource = Zoos; in OnAppearing() method






                  share|improve this answer












                  Add the BindingContext=this; after the InitializeComponent(); or else add CarouselZoos.ItemsSource = Zoos; in OnAppearing() method







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 at 12:29









                  Sujith Kumar

                  316




                  316






















                      up vote
                      1
                      down vote













                      Try this

                      First add this class, for property binding and implement the INotifyPropertyChanged structure to update the view.



                      public class ViewModelBase : INotifyPropertyChanged
                      {

                      string title = string.Empty;

                      /// <summary>
                      /// Gets or sets the title.
                      /// </summary>
                      /// <value>The title.</value>
                      public string Title
                      {
                      get { return title; }
                      set { SetProperty(ref title, value); }
                      }

                      string icon = string.Empty;

                      /// <summary>
                      /// Gets or sets the icon.
                      /// </summary>
                      /// <value>The icon.</value>
                      public string Icon
                      {
                      get { return icon; }
                      set { SetProperty(ref icon, value); }
                      }

                      bool isBusy;

                      /// <summary>
                      /// Gets or sets a value indicating whether this instance is busy.
                      /// </summary>
                      /// <value><c>true</c> if this instance is busy; otherwise, <c>false</c>.</value>
                      public bool IsBusy
                      {
                      get { return isBusy; }
                      set
                      {
                      SetProperty(ref isBusy, value);
                      }
                      }


                      /// <summary>
                      /// Sets the property.
                      /// </summary>
                      /// <returns><c>true</c>, if property was set, <c>false</c> otherwise.</returns>
                      /// <param name="backingStore">Backing store.</param>
                      /// <param name="value">Value.</param>
                      /// <param name="propertyName">Property name.</param>
                      /// <param name="onChanged">On changed.</param>
                      /// <typeparam name="T">The 1st type parameter.</typeparam>
                      protected bool SetProperty<T>(
                      ref T backingStore, T value,
                      [CallerMemberName]string propertyName = "",
                      Action onChanged = null)
                      {
                      if (EqualityComparer<T>.Default.Equals(backingStore, value))
                      return false;

                      backingStore = value;
                      onChanged?.Invoke();
                      OnPropertyChanged(propertyName);
                      return true;
                      }

                      /// <summary>
                      /// Occurs when property changed.
                      /// </summary>
                      public event PropertyChangedEventHandler PropertyChanged;
                      /// <summary>
                      /// Raises the property changed event.
                      /// </summary>
                      /// <param name="propertyName">Property name.</param>
                      protected void OnPropertyChanged([CallerMemberName]string propertyName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
                      }


                      Now when you got the base class for bind properties you can add a view model class for bind the properties and follow the MVVM pattern. I think this is the most property way to manipulate the data.



                      public class Zoo
                      {
                      public string ImageUrl { get; set; }
                      public string Name { get; set; }
                      }

                      public class CarouselViewModel : ViewModelBase
                      {
                      private ObservableCollection<Zoo> zoos;
                      public ObservableCollection<Zoo> Zoos
                      {
                      get => zoos; set => SetProperty(ref zoos, value);
                      }

                      public CarouselViewModel()
                      {
                      zoos = new ObservableCollection<Zoo>
                      {
                      new Zoo
                      {
                      ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/23c1dd13-333a-459e-9e23-c3784e7cb434/2016-06-02_1049.png",
                      Name = "Woodland Park Zoo"
                      },
                      new Zoo
                      {
                      ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/6b60d27e-c1ec-4fe6-bebe-7386d545bb62/2016-06-02_1051.png",
                      Name = "Cleveland Zoo"
                      },
                      new Zoo
                      {
                      ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/e8179889-8189-4acb-bac5-812611199a03/2016-06-02_1053.png",
                      Name = "Phoenix Zoo"
                      }
                      };
                      }
                      }
                      public partial class MainPage : ContentPage
                      {
                      public CarouselViewModel viewModel;
                      public MainPage()
                      {
                      InitializeComponent();
                      this.BindingContext = viewModel = new CarouselViewModel();
                      }
                      }





                      share|improve this answer





















                      • I changed the code as you specified, but the error remains the same: (
                        – Range
                        Nov 19 at 16:54










                      • Maybe it's the Xamarin Live Player, did you try to build on your phone or in the simulator? I try for myself and it works with no errors.
                        – Ivan-San
                        Nov 19 at 17:03










                      • Please, see first post
                        – Range
                        2 days ago















                      up vote
                      1
                      down vote













                      Try this

                      First add this class, for property binding and implement the INotifyPropertyChanged structure to update the view.



                      public class ViewModelBase : INotifyPropertyChanged
                      {

                      string title = string.Empty;

                      /// <summary>
                      /// Gets or sets the title.
                      /// </summary>
                      /// <value>The title.</value>
                      public string Title
                      {
                      get { return title; }
                      set { SetProperty(ref title, value); }
                      }

                      string icon = string.Empty;

                      /// <summary>
                      /// Gets or sets the icon.
                      /// </summary>
                      /// <value>The icon.</value>
                      public string Icon
                      {
                      get { return icon; }
                      set { SetProperty(ref icon, value); }
                      }

                      bool isBusy;

                      /// <summary>
                      /// Gets or sets a value indicating whether this instance is busy.
                      /// </summary>
                      /// <value><c>true</c> if this instance is busy; otherwise, <c>false</c>.</value>
                      public bool IsBusy
                      {
                      get { return isBusy; }
                      set
                      {
                      SetProperty(ref isBusy, value);
                      }
                      }


                      /// <summary>
                      /// Sets the property.
                      /// </summary>
                      /// <returns><c>true</c>, if property was set, <c>false</c> otherwise.</returns>
                      /// <param name="backingStore">Backing store.</param>
                      /// <param name="value">Value.</param>
                      /// <param name="propertyName">Property name.</param>
                      /// <param name="onChanged">On changed.</param>
                      /// <typeparam name="T">The 1st type parameter.</typeparam>
                      protected bool SetProperty<T>(
                      ref T backingStore, T value,
                      [CallerMemberName]string propertyName = "",
                      Action onChanged = null)
                      {
                      if (EqualityComparer<T>.Default.Equals(backingStore, value))
                      return false;

                      backingStore = value;
                      onChanged?.Invoke();
                      OnPropertyChanged(propertyName);
                      return true;
                      }

                      /// <summary>
                      /// Occurs when property changed.
                      /// </summary>
                      public event PropertyChangedEventHandler PropertyChanged;
                      /// <summary>
                      /// Raises the property changed event.
                      /// </summary>
                      /// <param name="propertyName">Property name.</param>
                      protected void OnPropertyChanged([CallerMemberName]string propertyName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
                      }


                      Now when you got the base class for bind properties you can add a view model class for bind the properties and follow the MVVM pattern. I think this is the most property way to manipulate the data.



                      public class Zoo
                      {
                      public string ImageUrl { get; set; }
                      public string Name { get; set; }
                      }

                      public class CarouselViewModel : ViewModelBase
                      {
                      private ObservableCollection<Zoo> zoos;
                      public ObservableCollection<Zoo> Zoos
                      {
                      get => zoos; set => SetProperty(ref zoos, value);
                      }

                      public CarouselViewModel()
                      {
                      zoos = new ObservableCollection<Zoo>
                      {
                      new Zoo
                      {
                      ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/23c1dd13-333a-459e-9e23-c3784e7cb434/2016-06-02_1049.png",
                      Name = "Woodland Park Zoo"
                      },
                      new Zoo
                      {
                      ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/6b60d27e-c1ec-4fe6-bebe-7386d545bb62/2016-06-02_1051.png",
                      Name = "Cleveland Zoo"
                      },
                      new Zoo
                      {
                      ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/e8179889-8189-4acb-bac5-812611199a03/2016-06-02_1053.png",
                      Name = "Phoenix Zoo"
                      }
                      };
                      }
                      }
                      public partial class MainPage : ContentPage
                      {
                      public CarouselViewModel viewModel;
                      public MainPage()
                      {
                      InitializeComponent();
                      this.BindingContext = viewModel = new CarouselViewModel();
                      }
                      }





                      share|improve this answer





















                      • I changed the code as you specified, but the error remains the same: (
                        – Range
                        Nov 19 at 16:54










                      • Maybe it's the Xamarin Live Player, did you try to build on your phone or in the simulator? I try for myself and it works with no errors.
                        – Ivan-San
                        Nov 19 at 17:03










                      • Please, see first post
                        – Range
                        2 days ago













                      up vote
                      1
                      down vote










                      up vote
                      1
                      down vote









                      Try this

                      First add this class, for property binding and implement the INotifyPropertyChanged structure to update the view.



                      public class ViewModelBase : INotifyPropertyChanged
                      {

                      string title = string.Empty;

                      /// <summary>
                      /// Gets or sets the title.
                      /// </summary>
                      /// <value>The title.</value>
                      public string Title
                      {
                      get { return title; }
                      set { SetProperty(ref title, value); }
                      }

                      string icon = string.Empty;

                      /// <summary>
                      /// Gets or sets the icon.
                      /// </summary>
                      /// <value>The icon.</value>
                      public string Icon
                      {
                      get { return icon; }
                      set { SetProperty(ref icon, value); }
                      }

                      bool isBusy;

                      /// <summary>
                      /// Gets or sets a value indicating whether this instance is busy.
                      /// </summary>
                      /// <value><c>true</c> if this instance is busy; otherwise, <c>false</c>.</value>
                      public bool IsBusy
                      {
                      get { return isBusy; }
                      set
                      {
                      SetProperty(ref isBusy, value);
                      }
                      }


                      /// <summary>
                      /// Sets the property.
                      /// </summary>
                      /// <returns><c>true</c>, if property was set, <c>false</c> otherwise.</returns>
                      /// <param name="backingStore">Backing store.</param>
                      /// <param name="value">Value.</param>
                      /// <param name="propertyName">Property name.</param>
                      /// <param name="onChanged">On changed.</param>
                      /// <typeparam name="T">The 1st type parameter.</typeparam>
                      protected bool SetProperty<T>(
                      ref T backingStore, T value,
                      [CallerMemberName]string propertyName = "",
                      Action onChanged = null)
                      {
                      if (EqualityComparer<T>.Default.Equals(backingStore, value))
                      return false;

                      backingStore = value;
                      onChanged?.Invoke();
                      OnPropertyChanged(propertyName);
                      return true;
                      }

                      /// <summary>
                      /// Occurs when property changed.
                      /// </summary>
                      public event PropertyChangedEventHandler PropertyChanged;
                      /// <summary>
                      /// Raises the property changed event.
                      /// </summary>
                      /// <param name="propertyName">Property name.</param>
                      protected void OnPropertyChanged([CallerMemberName]string propertyName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
                      }


                      Now when you got the base class for bind properties you can add a view model class for bind the properties and follow the MVVM pattern. I think this is the most property way to manipulate the data.



                      public class Zoo
                      {
                      public string ImageUrl { get; set; }
                      public string Name { get; set; }
                      }

                      public class CarouselViewModel : ViewModelBase
                      {
                      private ObservableCollection<Zoo> zoos;
                      public ObservableCollection<Zoo> Zoos
                      {
                      get => zoos; set => SetProperty(ref zoos, value);
                      }

                      public CarouselViewModel()
                      {
                      zoos = new ObservableCollection<Zoo>
                      {
                      new Zoo
                      {
                      ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/23c1dd13-333a-459e-9e23-c3784e7cb434/2016-06-02_1049.png",
                      Name = "Woodland Park Zoo"
                      },
                      new Zoo
                      {
                      ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/6b60d27e-c1ec-4fe6-bebe-7386d545bb62/2016-06-02_1051.png",
                      Name = "Cleveland Zoo"
                      },
                      new Zoo
                      {
                      ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/e8179889-8189-4acb-bac5-812611199a03/2016-06-02_1053.png",
                      Name = "Phoenix Zoo"
                      }
                      };
                      }
                      }
                      public partial class MainPage : ContentPage
                      {
                      public CarouselViewModel viewModel;
                      public MainPage()
                      {
                      InitializeComponent();
                      this.BindingContext = viewModel = new CarouselViewModel();
                      }
                      }





                      share|improve this answer












                      Try this

                      First add this class, for property binding and implement the INotifyPropertyChanged structure to update the view.



                      public class ViewModelBase : INotifyPropertyChanged
                      {

                      string title = string.Empty;

                      /// <summary>
                      /// Gets or sets the title.
                      /// </summary>
                      /// <value>The title.</value>
                      public string Title
                      {
                      get { return title; }
                      set { SetProperty(ref title, value); }
                      }

                      string icon = string.Empty;

                      /// <summary>
                      /// Gets or sets the icon.
                      /// </summary>
                      /// <value>The icon.</value>
                      public string Icon
                      {
                      get { return icon; }
                      set { SetProperty(ref icon, value); }
                      }

                      bool isBusy;

                      /// <summary>
                      /// Gets or sets a value indicating whether this instance is busy.
                      /// </summary>
                      /// <value><c>true</c> if this instance is busy; otherwise, <c>false</c>.</value>
                      public bool IsBusy
                      {
                      get { return isBusy; }
                      set
                      {
                      SetProperty(ref isBusy, value);
                      }
                      }


                      /// <summary>
                      /// Sets the property.
                      /// </summary>
                      /// <returns><c>true</c>, if property was set, <c>false</c> otherwise.</returns>
                      /// <param name="backingStore">Backing store.</param>
                      /// <param name="value">Value.</param>
                      /// <param name="propertyName">Property name.</param>
                      /// <param name="onChanged">On changed.</param>
                      /// <typeparam name="T">The 1st type parameter.</typeparam>
                      protected bool SetProperty<T>(
                      ref T backingStore, T value,
                      [CallerMemberName]string propertyName = "",
                      Action onChanged = null)
                      {
                      if (EqualityComparer<T>.Default.Equals(backingStore, value))
                      return false;

                      backingStore = value;
                      onChanged?.Invoke();
                      OnPropertyChanged(propertyName);
                      return true;
                      }

                      /// <summary>
                      /// Occurs when property changed.
                      /// </summary>
                      public event PropertyChangedEventHandler PropertyChanged;
                      /// <summary>
                      /// Raises the property changed event.
                      /// </summary>
                      /// <param name="propertyName">Property name.</param>
                      protected void OnPropertyChanged([CallerMemberName]string propertyName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
                      }


                      Now when you got the base class for bind properties you can add a view model class for bind the properties and follow the MVVM pattern. I think this is the most property way to manipulate the data.



                      public class Zoo
                      {
                      public string ImageUrl { get; set; }
                      public string Name { get; set; }
                      }

                      public class CarouselViewModel : ViewModelBase
                      {
                      private ObservableCollection<Zoo> zoos;
                      public ObservableCollection<Zoo> Zoos
                      {
                      get => zoos; set => SetProperty(ref zoos, value);
                      }

                      public CarouselViewModel()
                      {
                      zoos = new ObservableCollection<Zoo>
                      {
                      new Zoo
                      {
                      ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/23c1dd13-333a-459e-9e23-c3784e7cb434/2016-06-02_1049.png",
                      Name = "Woodland Park Zoo"
                      },
                      new Zoo
                      {
                      ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/6b60d27e-c1ec-4fe6-bebe-7386d545bb62/2016-06-02_1051.png",
                      Name = "Cleveland Zoo"
                      },
                      new Zoo
                      {
                      ImageUrl = "http://content.screencast.com/users/JamesMontemagno/folders/Jing/media/e8179889-8189-4acb-bac5-812611199a03/2016-06-02_1053.png",
                      Name = "Phoenix Zoo"
                      }
                      };
                      }
                      }
                      public partial class MainPage : ContentPage
                      {
                      public CarouselViewModel viewModel;
                      public MainPage()
                      {
                      InitializeComponent();
                      this.BindingContext = viewModel = new CarouselViewModel();
                      }
                      }






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 19 at 15:25









                      Ivan-San

                      31518




                      31518












                      • I changed the code as you specified, but the error remains the same: (
                        – Range
                        Nov 19 at 16:54










                      • Maybe it's the Xamarin Live Player, did you try to build on your phone or in the simulator? I try for myself and it works with no errors.
                        – Ivan-San
                        Nov 19 at 17:03










                      • Please, see first post
                        – Range
                        2 days ago


















                      • I changed the code as you specified, but the error remains the same: (
                        – Range
                        Nov 19 at 16:54










                      • Maybe it's the Xamarin Live Player, did you try to build on your phone or in the simulator? I try for myself and it works with no errors.
                        – Ivan-San
                        Nov 19 at 17:03










                      • Please, see first post
                        – Range
                        2 days ago
















                      I changed the code as you specified, but the error remains the same: (
                      – Range
                      Nov 19 at 16:54




                      I changed the code as you specified, but the error remains the same: (
                      – Range
                      Nov 19 at 16:54












                      Maybe it's the Xamarin Live Player, did you try to build on your phone or in the simulator? I try for myself and it works with no errors.
                      – Ivan-San
                      Nov 19 at 17:03




                      Maybe it's the Xamarin Live Player, did you try to build on your phone or in the simulator? I try for myself and it works with no errors.
                      – Ivan-San
                      Nov 19 at 17:03












                      Please, see first post
                      – Range
                      2 days ago




                      Please, see first post
                      – Range
                      2 days ago


















                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374192%2fcarouselview-in-xamarinforms%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      'app-layout' is not a known element: how to share Component with different Modules

                      android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                      WPF add header to Image with URL pettitions [duplicate]