Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7412759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:35:28+00:00 2026-05-29T06:35:28+00:00

The original use case: This is a possible use case I’m trying to solve:

  • 0

The original use case:

This is a possible use case I’m trying to solve:

  1. The user opens the page with my calendar set to the now date
  2. User selects a date a few months back
  3. User refreshes the page, causing the selected date in the VM to be reset to the now date

Expected: The calendar displays the now date

Actual: (with binding only on SelectedDate) The calendar only moves its selected date, but keeps showing the previously selected month

My solution:

In an MVVM scenario I am showing a Calendar control whose SelectedDate has a binding to a SelectedDate property in my ViewModel. The property in my VM triggers it’s PropertyChanged event when set.

The selected date in my VM can also be set from other parts in my code, so I want my calendar to always show the selected date (for example when another month is set as the selected date, I want my calendar to switch to that month). To get this behavior I also bound the DisplayDate property of my calendar to my SelectedDate property, and this gives me the expected behavior, except when I click on the gray dates of the previous or next month.

This is my Calendar in XAML:

<Calendar SelectedDate="{Binding Path=SelectedDate}" DisplayDate="{Binding Path=SelectedDate}" />

This the SelectedDate property in my ViewModel (implements INotifyPropertyChanged)

    public DateTime SelectedDate
    {
        get 
        { 
            return selectedDate; 
        }
        set 
        { 
            selectedDate = value;
            this.PropertyChanged(this, new PropertyChangedEventArgs("SelectedDate"));
        }
    }

The problem with the solution:

Apparently clicking on a gray date causes the SelectedDate to be set on mouse down and again on mouse up, which causes a selection of a date two months away.

Is there a better way to implement this kind of behavior? Or can I fix the DisplayDate problem (without too much hacking, meaning no/as little code as possible in code behind)?

All I really want is a SelecteDate property which also has the behavior of the DisplayDate property 🙂

Thank you for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:35:30+00:00Added an answer on May 29, 2026 at 6:35 am

    The way I have settled on fixing it now is in my code behind, on the loaded event of the calendar:

    private void CalendarLoaded(object sender, RoutedEventArgs e)
    {
        if (this.ViewStartCalendar.SelectedDate.HasValue)
        {
            this.ViewStartCalendar.DisplayDate = this.ViewStartCalendar.SelectedDate.Value;
        }
    }
    

    I would have rather done it in XAML or in my viewmodel, but I can live with this solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a newbie question to AJAX experts: In case an unauthenticated user tries
I want to use YUI Compressor (the original) and use it as part of
Original Question: i read that for RESTful websites. it is not good to use
I want to use a category to make a method on the original class
How to hide controller name in Url? I use the ASP.NET MVC. The original
So I'd like to do this: switch (keyPath) { case @refreshCount: //do stuff case
Based on this original idea, that many of you have probably seen before: http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-lisa/
Is it possible to actually use the Xcode debugger when running an iPhone app
Is it possible to extend more then one abstract class? I'm trying to convert
Some websites now use a JavaScript service from Tynt that appends text to copied

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.