ME-MarvinE / XCalendar

A plugin for .NET providing an API for representing a calendar along with fully customisable calendar controls for Xamarin Forms and .NET MAUI
MIT License
300 stars 36 forks source link

Unable to see Dates on Calendar on .Net Maui #77

Closed omxie closed 1 year ago

omxie commented 1 year ago

Describe the bug Pretty much followed the steps onto the wiki and can't get the calendar dates to be shown onto the UI. Just shows the header which is white and occupies space (because of the vertical options)

Expected behavior Show calendar view with dates.

Steps to reproduce OR link to code Please pull this Repository for reproduction of the bug

Xamarin Forms or .NET MAUI (If related to UI) Using .Net Maui, I have set the background as aqua just for debugging purposes. calendar

Additional context (Optional) Latest plugin version (4.2.0) Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.4.2

Device Info (Optional) Android Version: OS 12/API 31 (Simulator) Windows Version: 10.0.22621 Build 22621

ME-MarvinE commented 1 year ago

In order to link your page and ViewModel you must set the page's binding context to an instance of the ViewModel.

This can be done through XAML or code behind but I find code behind easier. In MainPage.Xaml.cs in the constructor you can do BindingContext = new CalendarViewModel();.

Next, in order for your page to know that a value is changed in the ViewModel, you need to raise the 'PropertyChanged' event you defined in BaseViewModel whenever you change the value of a property in your ViewModel.

private int _count;
public int Count
{
    get
    {
        return _count;
    }
    set
    {
        if (_count != value)
        {
            _count = value;
            OnPropertyChanged();
        }
    {

}

The reason this isn't required in the sample app is because it has a nuget package called 'PropertyChanged.Fody' which automatically injects the required stuff in the setter if it's a shorthand ({ get; set; }) property.

I'll make an example repo so people know how to use the Calendar from scratch since the one in the wiki's "Getting Started" page assumes prior knowledge of MVVM.

ME-MarvinE commented 1 year ago

Tested it in the repo you provided. Confirmed that adding BindingContext = new CalendarViewModel(); in CalendarView.xaml.cs causes the dates to show up.

image

omxie commented 1 year ago

Thanks! I tried it out and can confirm that it is indeed working.