<ContentPage.Behaviors>
<local:ScheduleBehavior/>
</ContentPage.Behaviors>
<ContentPage.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.05*"/>
<RowDefinition Height="0.95*"/>
</Grid.RowDefinitions>
<Button x:Name="button" Text="Add new Appointment"/>
<schedule:SfSchedule x:Name="schedule" Grid.Row="1"
DataSource = "{Binding Meetings}"
ScheduleView = "WeekView" >
<schedule:SfSchedule.AppointmentMapping>
<schedule:ScheduleAppointmentMapping
ColorMapping="Color"
EndTimeMapping="To"
StartTimeMapping="From"
SubjectMapping="EventName"
IsAllDayMapping="AllDay"/>
</schedule:SfSchedule.AppointmentMapping>
<schedule:SfSchedule.BindingContext>
<local:ViewModel/>
</schedule:SfSchedule.BindingContext>
</schedule:SfSchedule>
</Grid>
</ContentPage.Content> |
class ScheduleBehavior : Behavior<ContentPage>
{
SfSchedule schedule;
Button button;
protected override void OnAttachedTo(ContentPage bindable)
{
base.OnAttachedTo(bindable);
schedule = bindable.FindByName<SfSchedule>("schedule");
button = bindable.FindByName<Button>("button");
button.Clicked += AddAppointment;
schedule.MoveToDate = new DateTime(2018, 08, 30, 9, 0 ,0);
}
private void AddAppointment(object sender, EventArgs e)
{
var viewModel = schedule.BindingContext as ViewModel;
viewModel.Meetings.Add(new Meeting()
{
From = new DateTime(2018, 08, 30, 11, 0, 0),
To = new DateTime(2018, 08, 30, 13, 0, 0),
EventName = "New Appointment",
Color = Color.SaddleBrown
});
}
} |
private void AddAppointment(object sender, EventArgs e)
{
var viewModel = schedule.BindingContext as AppointmentViewModel;
// Get appointment from database
var table = (from i in database.Table<AppointmentDB>() select i);
foreach (var order in table)
{
viewModel.Meetings.Add(new Meeting()
{
EventName = order.Subject,
From = DateTime.Parse(order.StartTime),
To = DateTime.Parse(order.EndTime),
Color = Color.FromHex(order.Color),
AllDay = Convert.ToBoolean(order.AllDay),
});
}
} |
private void AddAppointment(object sender, EventArgs e)
{
var dataSource = schedule.DataSource as ObservableCollection<Meeting>;
var table = (from i in database.Table<AppointmentDB>() select i);
foreach (var order in table)
{
dataSource.Add(new Meeting()
{
EventName = order.Subject,
From = DateTime.Parse(order.StartTime),
To = DateTime.Parse(order.EndTime),
Color = Color.FromHex(order.Color),
AllDay = Convert.ToBoolean(order.AllDay),
});
}
} |