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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:42:34+00:00 2026-05-31T12:42:34+00:00

I have a WPF form that I have created programatically. It is basically a

  • 0

I have a WPF form that I have created programatically. It is basically a list of items with 2 DatePicker objects to specify a range of dates. I have everything working for the most part, but I need to fire some logic on the SelectedDateChanged event.

The problem is, since the DatePicker‘s are generated dynamically based on selections from a previous form, I need to use an anonymous listener (or whatever you call them in .NET). I have been unable to do it the way I know how and I cant seem to find any example or help through google either. Thanks in advance for any tips.

Generating DatePickers:

public SystemInterval(Role role)
    {
        this.role = role;
        InitializeComponent();
        lbls = new Label[role.RoleSystems.Length];
        dp = new DatePicker[role.RoleSystems.Length * 2];
        cks = new CheckBox[role.RoleSystems.Length];
        ScrollViewer sv = new ScrollViewer();
        sv.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
        sv.VerticalAlignment = System.Windows.VerticalAlignment.Top;
        sv.Margin = new Thickness(0,50,0,40);
        Grid g = new Grid();
        g.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
        g.VerticalAlignment = System.Windows.VerticalAlignment.Top;
        ColumnDefinition col1 = new ColumnDefinition();
        col1.Width = new GridLength(46);
        ColumnDefinition col2 = new ColumnDefinition();
        col2.Width = GridLength.Auto;
        ColumnDefinition col3 = new ColumnDefinition();
        col3.Width = new GridLength(150);
        ColumnDefinition col4 = new ColumnDefinition();
        col4.Width = new GridLength(150);
        g.ColumnDefinitions.Add(col1);
        g.ColumnDefinitions.Add(col2);
        g.ColumnDefinitions.Add(col3);
        g.ColumnDefinitions.Add(col4);
        sv.Content = g;
        LayoutRoot.Children.Add(sv);

        for (int r = 0; r < cks.Length; r++)
        {
            g.RowDefinitions.Add(new RowDefinition());
        }

        g.Height = (lbls.Length * 25) + (lbls.Length * 5);

        for (int i = 0, j = 0; i < cks.Length; i++, j+=2)
        {
            cks[i] = new CheckBox();
            cks[i].IsChecked = false;
            cks[i].VerticalAlignment = System.Windows.VerticalAlignment.Center;
            cks[i].HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            Grid.SetColumn(cks[i], 0);
            Grid.SetRow(cks[i], i);
            g.Children.Add(cks[i]);

            lbls[i] = new Label();
            lbls[i].Height = 25;
            lbls[i].Content = role.RoleSystems[i].SystemName;
            lbls[i].VerticalAlignment = System.Windows.VerticalAlignment.Center;
            lbls[i].HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            Grid.SetColumn(lbls[i], 1);
            Grid.SetRow(lbls[i], i);
            g.Children.Add(lbls[i]);

            dp[j] = new DatePicker();
            dp[j].Height = 25;
            dp[j].Width = 115;
            dp[j].VerticalAlignment = System.Windows.VerticalAlignment.Center;
            dp[j].HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            dp[j].IsEnabled = false;
            dp[j].BlackoutDates.Add(new CalendarDateRange(new DateTime(0001, 1, 1), DateTime.Now.Subtract(TimeSpan.FromDays(1))));
            Grid.SetColumn(dp[j], 2);
            Grid.SetRow(dp[j], i);
            g.Children.Add(dp[j]);

            dp[j + 1] = new DatePicker();
            dp[j + 1].Height = 25;
            dp[j + 1].Width = 115;
            dp[j + 1].VerticalAlignment = System.Windows.VerticalAlignment.Center;
            dp[j + 1].HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            dp[j + 1].IsEnabled = false;
            dp[j + 1].BlackoutDates.Add(new CalendarDateRange(new DateTime(0001, 1, 1), DateTime.Now));
            Grid.SetColumn(dp[j + 1], 3);
            Grid.SetRow(dp[j + 1], i);
            g.Children.Add(dp[j + 1]);

            cks[i].Click += new RoutedEventHandler(delegate(object s, RoutedEventArgs re)
            {
                CheckBox cb = (CheckBox)re.Source;
                for (int r = 0; r < cks.Length; r++)
                {
                    if (cks[r].Equals(cb))
                    {
                        dp[r * 2].IsEnabled = true;
                        dp[r * 2 + 1].IsEnabled = true;
                    }
                }
            });
        }

The checkboxs have an anonymous event handler, however this does not work for the DatePicker.SelectedDateChanged event.

  • 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-31T12:42:36+00:00Added an answer on May 31, 2026 at 12:42 pm

    Do you mean an event handler using an anonymous method like this?

    var dp = new DatePicker();
    dp.SelectedDateChanged +=
        (sender, args) =>
            {
                var picker = (DatePicker) sender;
                /* do stuff here */
            };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF form that uses ClientLogin to log a user into their
I have a main wpf form that opens a new form. However when that
I am creating a WPF form. One of the requirements is that it have
I have a WPF form that contains a DataGrid. This DataGrid is editable. One
I have an order entry form that has a ListBox with a list of
I have a WPF form that has a toolbar then a StackPanel under it
I have a WPF that creates buttons dynamically when the form is loaded and
In my WPF application, I have a ListView on the main form that displays
I have WPF Form which has many buttons with the same code. Appearance of
I have a WPF form and I am working with databinding. I get the

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.