如果想创建一个可滚动的时间线,我建议安装 Syncfusion.Xamarin.SfSchedule nuget 来实现。
这是 Xaml 的日期可滚动时间线示例代码:
<?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:syncfusion="clr-namespace:Syncfusion.SfCalendar.XForms;assembly=Syncfusion.SfCalendar.XForms"
xmlns:schedule="clr-namespace:Syncfusion.SfSchedule.XForms;assembly=Syncfusion.SfSchedule.XForms"
x:Class="XamarinTableView.Views.SyncCalendaPage">
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="Start"
HorizontalOptions="CenterAndExpand" />
<schedule:SfSchedule x:Name="schedule"
BackgroundColor="LightGray"
ScheduleView="DayView"
VerticalOptions="FillAndExpand"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
还有.cs 示例代码:
schedule.ScheduleView = ScheduleView.DayView;
ScheduleAppointmentCollection scheduleAppointmentCollection = new ScheduleAppointmentCollection();
scheduleAppointmentCollection.Add(new ScheduleAppointment()
{
StartTime = new DateTime(2020, 9, 24, 09, 0, 0),
EndTime = new DateTime(2020, 9, 24, 09, 30, 0),
Subject = "Client Meeting",
Notes="1111",
MinHeight = 30,
Color = Color.FromHex("#FFD80073")
});
scheduleAppointmentCollection.Add(new ScheduleAppointment()
{
StartTime = new DateTime(2020, 9, 24, 11, 0, 0),
EndTime = new DateTime(2020, 9, 24, 12, 30, 0),
Subject = "Anniversary",
Notes = "1111",
Color = Color.FromHex("#FFA2C139")
});
schedule.DataSource = scheduleAppointmentCollection;
DayViewSettings dayViewSettings = new DayViewSettings();
dayViewSettings.VerticalLineColor = Color.LightGray;
dayViewSettings.VerticalLineStrokeWidth = 5;
schedule.DayViewSettings = dayViewSettings;
效果:
也可以参考Appointments in Xamarin Scheduler (SfSchedule)自定义更多外观。