Guest User

Untitled

a guest
Feb 17th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Assignment6.MyPage">
  3. <ContentPage.Content>
  4. <StackLayout>
  5. <ListView x:Name = "ListviewItems" />
  6. <ListView.ItemTemplate>
  7. <DataTemplate>
  8. <ViewCell>
  9. <ViewCell.View>
  10. <StackLayout>
  11. <Label Text = "{Binding date}" />
  12. <Label Text = "{Binding meetingLocation}" />
  13. </StackLayout>
  14. </ViewCell.View>
  15. </ViewCell>
  16. </DataTemplate>
  17. </ListView.ItemTemplate>
  18. </StackLayout>
  19.  
  20. </ContentPage.Content>
  21. </ContentPage>
  22.  
  23. namespace Assignment6
  24. {
  25. [XamlCompilation(XamlCompilationOptions.Compile)]
  26. public partial class MyPage : ContentPage
  27. {
  28. private ObservableCollection<Reservation> items = new ObservableCollection<Reservation>();
  29. public MyPage()
  30. {
  31. InitializeComponent();
  32.  
  33. Init();
  34.  
  35. }
  36.  
  37. public void Init()
  38. {
  39. BindingContext = new Reservation();
  40. var enumerator = App.UserDatabase.GetReservation();
  41.  
  42. while (enumerator.MoveNext())
  43. {
  44. items.Add(enumerator.Current);
  45. }
  46. ListviewItems.ItemsSource = items;
  47.  
  48.  
  49. }
  50. }
  51. }
  52.  
  53. public class Reservation
  54. {
  55. [PrimaryKey][AutoIncrement]
  56. public int date { get; set; }
  57. public int startingTime { get; set; }
  58. public string duration { get; set; }
  59. public int meetingLocation { get; set; }
  60.  
  61.  
  62. public Reservation()
  63. {
  64. }
  65.  
  66. public Reservation(int date, int startingTime, string duration, int meetingLocation)
  67. {
  68. this.date = date;
  69. this.startingTime = startingTime;
  70. this.duration = duration;
  71. this.meetingLocation = meetingLocation;
  72.  
  73.  
  74. }
  75. }
  76.  
  77. void Handle_Clicked(object sender, System.EventArgs e)
  78. {
  79. DisplayAlert("Reservation", "Your reservation for a " + Output.Text + " meeting in room " + Room.SelectedIndex +
  80. " starting at " + Time.Time + " on " + Date.Date.Month + "/" + Date.Date.Day + "/" + " " + Date.Date.Year + " for " + Slide.Value.ToString() + " hours has been added.", "OK");
  81. Reservation reserve = new Reservation(Date.Date.Month, Time.Time.Hours, Slide.Value.ToString(), Room.SelectedIndex);
  82.  
  83.  
  84. App.UserDatabase.SaveReservation(reserve);
  85.  
  86.  
  87. }
  88.  
  89. System.InvalidCastException: Specified cast is not valid.
  90. at Xamarin.Forms.ItemsView`1+<>c[TVisual].<.cctor>b__24_0 (Xamarin.Forms.BindableObject b, System.Object v) [0x00000] in D:a1sXamarin.Forms.CoreItemsView.cs:25
  91. at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00071] in D:a1sXamarin.Forms.CoreBindableObject.cs:387
  92. at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x0003d] in D:a1sXamarin.Forms.CoreBindableObject.cs:573
  93. at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:a1sXamarin.Forms.CoreBindableObject.cs:99
  94. at Assignment6.MyPage.InitializeComponent () [0x00023] in /Users/zane/Projects/Assignment6/Assignment6/obj/Debug/netstandard2.0/MyPage.xaml.g.cs:26
  95. at Assignment6.MyPage..ctor () [0x00013] in /Users/zane/Projects/Assignment6/Assignment6/MyPage.xaml.cs:16
  96. at Assignment6.MainPage+<Handle_Clicked_1>d__2.MoveNext () [0x0000f] in /Users/zane/Projects/Assignment6/Assignment6/MainPage.xaml.cs:33
  97. at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.13/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1023
  98. at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.13/src/Xamarin.iOS/Foundation/NSAction.cs:178
  99. at at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  100. at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.13/src/Xamarin.iOS/UIKit/UIApplication.cs:79
  101. at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.13/src/Xamarin.iOS/UIKit/UIApplication.cs:63
  102. at Assignment6.iOS.Application.Main (System.String[] args) [0x00001] in /Users/zane/Projects/Assignment6/Assignment6.iOS/Main.cs:17
Add Comment
Please, Sign In to add comment