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 965701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:02:26+00:00 2026-05-16T02:02:26+00:00

just some code…: Question is at bottom. XAML : <StackPanel Orientation=Horizontal> <Button Content=Start Command={Binding

  • 0

just some code…: Question is at bottom.

XAML:

 <StackPanel Orientation="Horizontal">
            <Button Content="Start" Command="{Binding FirstDateCommand}" />
            <Button Content="Back" Command="{Binding PreviousDateCommand}" />
            <DatePicker SelectedDate="{Binding SelectedDate}" DisplayDateStart="{Binding MinDate}" DisplayDateEnd="{Binding MaxDate}" />
            <Button Content="Forward" Command="{Binding NextDateCommand}"  />
            <Button Content="End" Command="{Binding LastDateCommand}" />
        </StackPanel>

ViewModel:

public class LessonPlannerViewModel : ViewModelBase
    {    
        private ILessonPlannerRepository _lessonplannerRepo;    

        private ObservableCollection<LessonDay> _lessons;

        private RelayCommand _firstDateCommand;
        private RelayCommand _lastDateCommand;
        private RelayCommand _nextDateCommand;
        private RelayCommand _previousDateCommand;

        public LessonPlannerViewModel()
        {
            _lessonplannerRepo = new LessonPlannerRepository();

            MinDate = DateTime.Now.AddDays(-2);
            MaxDate = DateTime.Now.AddDays(2);

            SelectedDate = DateTime.Now;                   
        }

        public RelayCommand FirstDateCommand
        {
            get { return _firstDateCommand ?? (_firstDateCommand = new RelayCommand(() => MoveFirstDate(), () => CanMoveFirstDate())); }
        }

        public RelayCommand LastDateCommand
        {
            get { return _lastDateCommand ?? (_lastDateCommand = new RelayCommand(() => MoveLastDate(), () => CanMoveLastDate())); }
        }

        public RelayCommand PreviousDateCommand
        {
            get { return _previousDateCommand ?? (_previousDateCommand = new RelayCommand(() => MovePreviousDate(), () => CanMovePreviousDate())); }
        }

        public RelayCommand NextDateCommand
        {
            get { return _nextDateCommand ?? (_nextDateCommand = new RelayCommand(() => MoveNextDate(), () => CanMoveNextDate())); }
        }

        private void MoveFirstDate()
        {
            SelectedDate = MinDate;
            Lessons = _lessonplannerRepo.GetLessonDayByDate(SelectedDate);
        }

        private void MoveLastDate()
        {
            SelectedDate = MaxDate;
            Lessons = _lessonplannerRepo.GetLessonDayByDate(SelectedDate);
        }

        private void MoveNextDate()
        {
            SelectedDate = SelectedDate.AddDays(1);
            Lessons = _lessonplannerRepo.GetLessonDayByDate(SelectedDate);
        }

        private void MovePreviousDate()
        {
            SelectedDate = SelectedDate.AddDays(-1);
            Lessons = _lessonplannerRepo.GetLessonDayByDate(SelectedDate);
        }

        private bool CanMoveFirstDate()
        {
            return SelectedDate != MinDate;
        }

        private bool CanMoveLastDate()
        {
            return SelectedDate != MaxDate;
        }

        private bool CanMoveNextDate()
        {
            return SelectedDate < MaxDate;
        }

        private bool CanMovePreviousDate()
        {
            return SelectedDate > MinDate;
        }   

        private DateTime _selectedDate;
        public DateTime SelectedDate
        {
            get { return _selectedDate; }
            set
            {
                if (_selectedDate == value)
                    return;

                _selectedDate = value;
                this.RaisePropertyChanged("SelectedDate");
                //Lessons = _lessonplannerRepo.GetLessonDayByDate(SelectedDate);
            }
        }

        public DateTime MinDate { get; set; }

        public DateTime MaxDate { get; set; }        

        public ObservableCollection<LessonDay> Lessons
        {
            get { return _lessons; }
            set
            {
                _lessons = value;
                this.RaisePropertyChanged("Lessons");
            }
        }
...

When I choose in the DatePicker a date which is equal to MinDate then the PreviousDateCommand returns CanExecute = false; thats ok and works as expected.

But why is the LastDateCommand not returning CanExecute = false too?

My CanExecute logic works as expected, when I press the PreviousDateButton instead of selecting the date via datepicker.

What do I wrong?

UPDATE:

I have not had any doubts that my logic is wrong but… I tried some things and with this code

this is really weird. I changed now the logic of the LastDate and PreviousDate CanExecute method and both buttons work now changing the datepicker.

private bool CanMoveFirstDate()
{
    Debug.WriteLine("SelectedDate FirstDate: " + SelectedDate);
    return SelectedDate > MinDate;
}

private bool CanMovePreviousDate()
{
    Debug.WriteLine("SelectedDate PreviousDate: " + SelectedDate);
    return SelectedDate > MinDate;
}

Is someone knows how to make the NextDate + LastDate button working gets the solution! 😛

UPDATE 2:

Bindings are powerfull but maybe hard to control…

I did some crazy logic shit again and now it seems to work:

        private bool CanMoveNextDate()
        {
            Debug.WriteLine("SelectedDate NextDate: " + SelectedDate);
            return SelectedDate.AddDays(1) < MaxDate;
        }

        private bool CanMoveLastDate()
        {
            Debug.WriteLine("SelectedDate LastDate: " + SelectedDate);
            return SelectedDate.AddDays(1) < MaxDate;
        }  

If someone can explain that weird logic, that would be nice , I think the cause lays in the binding of the datepicker and the commands and which binding gets updated first or is called etc…

  • 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-16T02:02:26+00:00Added an answer on May 16, 2026 at 2:02 am

    tststs… this is really a lesson to me:

    Instead of putting this is the viewmodel constructor:

    MinDate = DateTime.Now.AddDays(-2);
    MaxDate = DateTime.Now.AddDays(2);
    

    put this:

    MinDate = DateTime.Parse("28.07.2010 00:00:00");
    MaxDate = DateTime.Parse("01.08.2010 00:00:00");
    

    because SelectedDate is always formatted like this:

    dd.MM.yyyy 00:00:00
    

    I want to say Microsoft thank you for their great debugging tools in VS 2010 =>

    http://img833.imageshack.us/img833/5912/cryforariver.png

    and I already cursed the wpf binding system 😛 a god damn user error now go and slap me I

    deserve it! but the points are mine 😛

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

Sidebar

Related Questions

Right now, I've just some code which fetches the picture from the URL directly.
Just some example code here, but I have lists of strings that I want
I just wrote some code to test the behavior of std::equal, and came away
I just saw some code in our code base (and it's OLD code, as
I just declared some code-first models for a new project that uses EntityFramework. public
I just opened some old code in the current Eclipe Juno Release Candidate and
this is just some pretty standard code I have tried. What I am trying
I've just found some C++ code (at http://msdn.microsoft.com/en-us/library/k8336763(VS.71).aspx ), which uses a technique I've
I was just editing some C# code between <% %> tags in an .ascx
I was just trying out some code, not a experienced coder. I implemented(at least

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.