【问题标题】:Xamarin XLabs Forms CalendarView not working on AndroidXamarin XLabs Forms CalendarView 无法在 Android 上运行
【发布时间】:2016-04-09 17:01:59
【问题描述】:

我在 Xamarin Studio 的 XLabs Nuget 包中使用 Xamarin Forms 中的 CalendarView 控件。

CalendarView 定义如下,但安卓设备上没有显示日历:

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
            }
        };
    }
}
}

【问题讨论】:

    标签: android xamarin xamarin.forms calendarview xlabs


    【解决方案1】:

    记得用

    初始化MainActivity
    MainActivity : XFormsApplicationDroid
    

    并将 XLabs 也添加到 Droid 项目中。它现在正在工作。

    【讨论】:

      【解决方案2】:

      请使用下面的代码,它会工作的

      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,
                                   },
                              }));
      

      【讨论】:

        猜你喜欢
        • 2017-09-04
        • 1970-01-01
        • 1970-01-01
        • 2018-03-01
        • 2019-06-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多