manton
manton

Reputation: 561

Bring selected calendar date into view

I select a date (not the current date) of a calendar (wpf) by code (C#). Now I want to bring this selected date into view. How can I solve that? All the time the current date is in view.

Any ideas to that? Thank you!

Upvotes: 5

Views: 3212

Answers (1)

Shimmy Weitzhandler
Shimmy Weitzhandler

Reputation: 104702

You have to set the DisplayDate property as well.

var date = DateTime.Now.AddYears(-10);
cal.SelectedDate = date;
cal.DisplayDate = date;

enter image description here

You may also want to set the SelectionMode property to set the range of dates allowed (CalendarSelectionMode enumeration).

Upvotes: 5

Related Questions