Closed mario-aleo closed 9 years ago
I'm happy to help, and perhaps update the Readme as needed, but I'd like to understand where the problem is (that is, where I went wrong in communicating usage). Did you try accessing the static "CrossCalendars.Current" as mentioned in the Readme? That property is an ICalendars, which has comments for all its methods, so I was sort of counting on intellisense to take it from there in telling you what the methods were and how to use them. Curious if I made a false assumption here.
For your specific use, listing the events needs a calendar and a time range. CrossCalendars.Current.GetCalendarsAsync will return all the calendars on the device. From there you can select one and use CrossCalendars.Current.GetEventsAsync for the events.
Sorry, now I've got but, but I'm stuck in a way to get calendar by calendar from CrossCalendars.Current.GetCalendarsAsync to use then in the CrossCalendars.Current.GetEventsAsync.
Thanks for the support.
Sorry, I don't quite understand what you're trying to do or what the problem is.
Sorry, let me try to explain, CrossCalendars.Current.GetCalendarsAsync will return a list of calendars, once that some platforms like iOS keep more than one calendars in it, but the list is not an array and it seems not to be returning one by one calendar, it's returning the complete list. My question is, how can I get the calendar name from the list, one by one, if it`s not an array?
Thanks.
Er, it's not an array, but it is a list. Or is the Task part throwing you?
var calendars = await CrossCalendars.Current.GetCalendarsAsync(); foreach (var calendar in calendars) { ... }
Maybe something like this so... although it isn't displaying anything
public List<string> listEvents = new List<string>();
public MainContent ()
{
InitializeComponent ();
getList ();
var stackLayout = new StackLayout { Padding = 30, Spacing = 30 };
var list = new ListView ();
stackLayout.Children.Add (list);
list.ItemsSource = listEvents;
}
public async void getList()
{
var listCalendars = await CrossCalendars.Current.GetCalendarsAsync();
foreach(var calendar in listCalendars)
{
var events = await CrossCalendars.Current.GetEventsAsync(calendar, DateTime.Now, DateTime.Now.AddYears(1));
foreach (var calendarEvent in events)
{
listEvents.Add(calendarEvent.ToString());
}
}
}
I would expect that to work, assuming that your app has permission to access the calendar and there are actually events within the next year. Note that an issue like not having permission would throw an exception, which would be lost in your async void method (my other GitHub project, AsyncVoidAnalyzer, would be showing red squiggles).
Got it working, but the list is only displayed if I change the state of the device (if I change the orientation).
Thanks for all your support.
Oh, that probably has to do with the fact that you're binding your Xamarin.Forms ListView to a List instead of ObservableCollection, so it doesn't know to update when you add the calendar entries to it.
Hello,
Sorry, but I don't have a clue about how to use the calendar plugin, if someone could help me, I'll appreciate. I would like to know what are the methods, how to call than and what is their callbacks, specially about how list the events.
Thanks.