Search code examples
xamarinxamarin.formscalendarcalendarviewappointment

How to add activity(Appointments, Tasks) in Xamarin.Forms by using calendar control inside applicatoin?


I am creating an application and in that there is a need to display calendar inside the particular page or block and inside the calendar there are display particular activity on the day like on 27th April it display 4th Saturday and so on depend on the run time.

I am using .Net standard 2.0 and try to make with XamForms.Controls.Calendar but it doesn't work for me.

I need to implement calendar with free plugin and full .Net standard support.

Can anyone look into this and suggest me what should I have to change in code or configuration?


Solution

  • If you just want to display the particular activity on specific day, you can use SpecialDate in XamForms.Controls.Calendar to achieve that, I set the FontSize = 0 to make the date invisable and set Selectable = false to disable the select action:

        public MainPage()
        {
            InitializeComponent();
    
            Calendar calendar = new Calendar
            {
                MaxDate = DateTime.Now.AddDays(30),
                MinDate = DateTime.Now.AddDays(-1),
                MultiSelectDates = false,
                DisableAllDates = false,
                WeekdaysShow = true,
                ShowNumberOfWeek = true,
    
                ShowNumOfMonths = 1,
                EnableTitleMonthYearView = true,
                WeekdaysTextColor = Color.Teal,
                StartDay = DayOfWeek.Monday,
                SelectedTextColor = Color.Fuchsia,
                SpecialDates = new List<SpecialDate>{
                    new SpecialDate(DateTime.Now.AddDays(2))
                    {
                        BackgroundColor = Color.White,
                        TextColor = Color.White,
    
                        Selectable = false,
                        FontSize = 0,
    
                        BackgroundPattern = new BackgroundPattern(1)
                        {
                            Pattern = new List<Pattern>
                            {
                                new Pattern{ WidthPercent = 1f, HightPercent = 1f, Color = Color.White,Text = "4th Saturday", TextColor=Color.DarkBlue, TextSize=8, TextAlign=TextAlign.Middle}
                            }
                        }
                    }
                }
            };
    
            Content = new ScrollView
            {
                Content = new StackLayout
                {
                    Padding = new Thickness(5, Device.RuntimePlatform == Device.iOS ? 25 : 5, 5, 5),
                    Children = {
                            calendar//,c2
                        }
                }
            };        
    
        }
    

    Here is the result:

    calendarview

    If you want to show all the Saturday, you should calculate the date yourself and pass the date as a parameter in DateTime.Now.AddDays(2).