Search code examples
c#wpfdatetimepicker

Disable all the dates except a specific date in calendar in wpf


I'd like to disable all the dates of each month except a specific date (say 6th of each month) in a datepicker so that user can only select this specific date of each month in my wpf app. Is it possible? Many thanks.


Solution

  • You can use the ComboBox if you want the user to select only month and year. You can do something like this.

     <ComboBox Name="Month" Margin="40,100,324,191"  Selected="Month_Selected_1">
            <ComboBoxItem Content="Jan"></ComboBoxItem>
            <ComboBoxItem Content="Feb"></ComboBoxItem>
      </ComboBox>
      <ComboBox Name="Year" Margin="227,100,143,199" Selected="Year_Selected_1" >
            <ComboBoxItem Content="1991"></ComboBoxItem>
      </ComboBox>
    

    Then in the Selected event.

    ComboBoxItem typeItem = Year.SelectedItem as ComboBoxItem;
    string selectedYear = typeItem.Content.ToString();
    

    Instead of adding elements in the XAML ,do it in code behind or use binding.