I am creating a dynamic carousel view in my Xamarin app, and so far it works just fine, but...
My carousel contains students and each carousel page is a link to a student info page. I want to be able to set an object with the current selected student for me to grab on all the students subpages (hope this makes sense :-/).
My script is as follow.
StudentModel:
public class StudentData { public string id { get; set; } public string name { get; set; } public string course { get; set; } public string schoolclass { get; set; } public string profileImage { get; set; } }
CarouselPart:
ObservableCollection<StudentData> collection = new ObservableCollection<StudentData>(); collection.Add(new StudentData { name = "Soren Hanson", schoolclass = "4. grade", course = "Math" }); collection.Add(new StudentData { name = "Michael Trane", schoolclass = "7. grade", course = "English" }); collection.Add(new StudentData { name = "Tammy Jump", schoolclass = "1. grade", course = "English" }); DataTemplate template = new DataTemplate(() => { var imageBtn = new Button(); imageBtn.Image = "Images/default.png"; imageBtn.Clicked += delegate { // ADDING THE CURRENT STUDENT TO MY CURRSTUDENT OBJECT // //App.currStudent = collection....... var menteeOptions = new MenteeOptions(); imageBtn.Navigation.PushAsync(menteeOptions); } } carousel.ItemTemplate = template; carousel.PositionSelected += pageChanged; carousel.ItemsSource = collection;
Hoping for help with this and thanks in advance :-)
1 Answers
Answers 1
Well you question was quite confusing at first but I will answer it from what I understood you want to keep the selected student object with you on your subpages:
So you can either use SQLite for it which can be found here
Or you can just maintain it as a static system object on your app.xaml.cs and use it
Something like this
App.Xaml.cs
public static object YourDataHolder {get; set;}
In your clicked event:
imageBtn.Clicked += delegate { // ADDING THE CURRENT STUDENT TO MY CURRSTUDENT OBJECT // App.YourDataHolder = _yourCollection; var menteeOptions = new MenteeOptions(); imageBtn.Navigation.PushAsync(menteeOptions); }
The use it something like this :
fooObject=App.YourDataHolder as FooType;
0 comments:
Post a Comment