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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:25:09+00:00 2026-06-12T11:25:09+00:00

I have a viewmodel that contains a pair of DateTime? objects – nullable DateTimes.

  • 0

I have a viewmodel that contains a pair of DateTime? objects – nullable DateTimes.

private DateTime? _xmitdtFrom;
public DateTime? xmitdtFrom
{
    get { return this._xmitdtFrom; }
    set
    {
        this._xmitdtFrom = value;
        notifyPropertyChanged("xmitdtFrom");
    }
}

private DateTime? _xmitdtTo;
public DateTime? xmitdtTo
{
    get { return this._xmitdtTo; }
    set
    {
        this._xmitdtTo = value;
        notifyPropertyChanged("xmitdtTo");
    }
}

The xmitdtFrom date cannot be greater than the xmitdtFrom date, the xmitdtTo date cannot be before the xmitdtFrom date, and neither the xmitdtTo date not the xmitdtFrom can be after today.

So, in the markup I have this:

<Label Grid.Row="1" Grid.Column="1">
    From:
</Label>
<DatePicker Grid.Row="1" Grid.Column="2" 
        SelectedDate="{Binding xmitdtFrom, Mode=TwoWay}"
        DisplayDateEnd="{Binding xmitdtTo}"
        />
<Label Grid.Row="2" Grid.Column="1">
    Through:
</Label>
<DatePicker Grid.Row="2" Grid.Column="2"
        SelectedDate="{Binding xmitdtTo, Mode=TwoWay}"
        DisplayDateStart="{Binding xmitdtFrom}"
        DisplayDateEnd="{x:Static sys:DateTime.Now}"
        />

And this works fine, unless xmitdtTo is null – in which case xmitdtFrom is unrestricted, which is a problem.

What I want is to set DisplayDateEnd for the xmitdtFrom to the xmitdtTo, if it’s not null, or to DateTime.Now, if it is.

And I’m wondering what might be the cleanest way of accomplishing this.

  • 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-06-12T11:25:10+00:00Added an answer on June 12, 2026 at 11:25 am

    I decided to go with another approach entirely.

    Instead of messing about with the viewmodel, I created an IfNullConverter, that when used in a binding would pass the bound object, if it was not null, or would pass its ConversionParameter, if it was.

    And I used that in binding the from date’s DisplayDateEnd – with xmitDTTo as the bound property, and DateTime.Now as the ConversionParameter.

    Solves the problem cleanly, entirely within the UI (and this is a UI problem, not a data problem, so I’d prefer a solution that doesn’t pollute the viewmodel). And it creates a general purpose functionality, that will be available to use in other similar circumstances.

    The converter:

    public class IfNullConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return parameter;
            else
                return value;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    The binding:

    <DatePicker Grid.Row="1" Grid.Column="2" 
        SelectedDate="{Binding Path=xmitdtFrom, Mode=TwoWay}"
        DisplayDateEnd="{Binding xmitdtThrough, Converter={StaticResource ifNullConverter}, ConverterParameter={x:Static sys:DateTime.Now}}"
        />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ViewModel that contains two objects: public class LookUpViewModel { public Searchable
I have a viewmodel that contains a product and SelectList of categories. public class
I have a viewmodel that contains a number of properties, a SelectList, and an
I have a ViewModel that contains a Product type and an IEnumerable< Product >
I have a ViewModel class that contains a list of points, and I am
I have a Usercontrol(TabUserControl) which contains a TabControl. The Viewmodel of that UserControl loads
I have a window that uses a viewmodel. This screen contains 2 listviews on
Using MVC2, I have a simple ViewModel that contains a bool field that is
I have a MainView that contains a scrollViewer, from its ViewModel I have a
I have a view that I pass a viewmodel object to that contains an

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.