C# and WPF Calendar Control

Sphiwe 1 Reputation point
2022-09-14T19:01:01.247+00:00

I want to be able to highlight multiple dates from a list in a calendar control on WPF.

Developer technologies | Windows Presentation Foundation
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Hui Liu-MSFT 48,676 Reputation points Microsoft External Staff
    2022-09-15T02:36:29.873+00:00

    Hi,@Sphiwe . Welcome Microsoft Q&A. For highlighting multiple dates on the calendar, you could refer to the code below.

    Xaml:
    241229-highlight-multiple-days-on-calendar.txt
    Codebehind:

     public class MainViewModel  
        {  
            public List<DateTime> Dates { get; } = new List<DateTime>();  
      
            public MainViewModel()  
            {  
                this.Dates.Add(DateTime.Today);  
                this.Dates.Add(DateTime.Today.AddDays(1));  
                this.Dates.Add(DateTime.Today.AddDays(5));  
                this.Dates.Add(DateTime.Today.AddDays(-3));  
            }  
        }  
        public class MyCalendarConverter : IMultiValueConverter  
        {  
            public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)  
            {  
                var date = (DateTime)values[0];  
                var dates = values[1] as List<DateTime>;  
                return dates.Contains(date);  
            }  
            public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)  
            {  
                throw new NotImplementedException();  
            }  
        }  
    

    ----------------------------------------------------------------------------

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.