简体   繁体   中英

Xamarin XLabs Forms CalendarView not working on Android

I'm using the CalendarView control in Xamarin Forms from the XLabs Nuget package in Xamarin Studio.

The CalendarView is defined as below, but no Calendar is shown on the android device:

using System;

using Xamarin.Forms;
using XLabs.Forms.Controls;

namespace CustomRenderer
{
public class MyPage : ContentPage
{
    public MyPage()
    {
        CalendarView calendarView = new XLabs.Forms.Controls.CalendarView 
            {
                MinDate = new DateTime(2016, 1,1),
                MaxDate = new DateTime(2016, 1, 31),
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                ShowNavigationArrows = true,

                DateBackgroundColor = Color.White,
                IsVisible = true,
            };

        calendarView.DateSelected += (object sender, DateTime e) => {

        };
        Content = new StackLayout
        { 

                HeightRequest = 400,
                WidthRequest = 320,
            Children =
            {
                calendarView
            }
        };
    }
}
}

Remember to initialize the MainActivity with

MainActivity : XFormsApplicationDroid

AND add XLabs to the Droid project as well. It's working now.

Please use below code, It will work

var MinDt = new DateTime(1970, 1, 1);
                        var MaxDt = new DateTime(2070,1,1);
                        Pages.Add(id, new CarlNavPage(new ContentPage
                        {

                            Content = new CalendarView() {
                                MinDate = CalendarView.FirstDayOfMonth(MinDt),
                                MaxDate = CalendarView.LastDayOfMonth(MaxDt),
                                HighlightedDateBackgroundColor = Color.FromRgb(227, 227, 227),
                                MonthTitleBackgroundColor = Color.FromHex("#f1eff5"),
                                ShouldHighlightDaysOfWeekLabels = false,
                                SelectionBackgroundStyle = CalendarView.BackgroundStyle.Fill,
                                TodayBackgroundStyle = CalendarView.BackgroundStyle.CircleOutline,
                                BackgroundColor = Color.FromHex("#f1eff5"),
                                HighlightedDateForegroundColor = Color.FromHex("#f1eff5"),
                                //  HighlightedDaysOfWeek = new DayOfWeek[] { DayOfWeek.Saturday, DayOfWeek.Sunday },
                                ShowNavigationArrows = true,
                             },
                        }));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM