DatePicker day of week RRS feed

  • Question

  • I have a datepicker in my windows app.  I want the user to be able to pick a date based on the day of the week.  I set the property DayFormat to {dayofweek.full}.  I also set MonthVisible and YearVisibile to false.  With that, the datepicker shows the dropdown with the days of the week.  However, it shows the days of the week multiple times.  How do I have the days of the week appear only once.
    Tuesday, August 12, 2014 7:37 PM


  • Hi querty,

    if you just want to allow the user to select a Day, you shouldn't use the "Date"-Picker. The DatePicker is to pick a date. So in your case the user sees all the Days of a single month, that's why the days are repeated.

    What can you do instead:

    Use a classical ComboBox, cause you just care about a day:

       <ComboBox x:Name="comboBox" Width="200"/>

    Set it's ItemsSource-Property to seven days. You could even use the DateTime-class to grab exactly those names from it:

             comboBox.ItemsSource = Enumerable.Range(1, 7)
                        .Select(day => new DateTime(2014, 1, day + 5 /* starting with a Monday */).ToString("dddd"))

    Note that the DateTime-objects themselves aren't used. I've just used an arbitrary date and start with a monday (6th January 2014) to get the days Monday to Sunday.

    And instead of using the codebehind-file, you could also do it completely in XAML:

        <ComboBox VerticalAlignment="Center" Width="200">

    Thomas Claudius Huber

    "If you can't make your app run faster, make it at least look & feel extremly fast"

    My latest Pluralsight-course: Windows Store Apps - Data Binding in Depth

    twitter: @thomasclaudiush
    homepage: www.thomasclaudiushuber.com
    author of: ultimate Windows Store Apps handbook | ultimate WPF handbook | ultimate Silverlight handbook

    Tuesday, August 12, 2014 8:07 PM