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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:07:34+00:00 2026-05-26T18:07:34+00:00

I think the title for this question is probably wrong, but I’m not sure

  • 0

I think the title for this question is probably wrong, but I’m not sure quite how to phrase it. I have a C# 4.0 (VS2010) WPF application.

This application consists of a single window with a header including the basics (logos, captions, etc) and a set of navigation buttons (back, retry, next, etc). The rest of the window is comprised of a listbox that is populated with one or more usercontrols based on what mode the app is currently in.

The way the code is currently written when the mode changes the listbox is cleared, all new user controls are added, and the buttons are set to their required state. This is fine for the initial state of each window mode but I’m having trouble deciding a good approach to update the navigation buttons as the contents of the controls change.

For example one screen is a configuration screen and there are three user controls contained within the listbox. These controls are custom classes that inherit from UserControl. Additionally they implement an interface that defines a method ‘bool Validate’ which determines if the control has been completely filled out.

This same scenario could apply to lots of other situations but this is a generic use case that is pretty straightforward to understand. When the screen initially loads the ‘Next’ button, whose visibility is controled by the parent window, is visible but disabled as the child controls can’t possibly yet be valid. At some point as the user fills out arbitrary data within one or more controls each one would return true if its Validate method was called.

At the point where all controls are valid, the next button would then become enabled. Fairly straightforward design.

The problem is each control doesn’t know what screen it is on, and this is by design. I don’t want the controls having to be aware of each other and updating a button status in the parent window. I also don’t want the parent window to run a polling thread to call Validate every second because in some cases the validation could be complex.

I’m thinking that the change event of each control within the UserControl (text boxes, radio buttons, etc) would all call a trigger a private validate event and this would set some public property on the interface or class.

f I can do that is there a way for the parent window to respond in an event-driven manner to the change of that property? I’m not looking to do this in WPF, doing this in C# code is preferable as I don’t want to get into the complexity of WPF quite yet. I’m just not sure, other than constant polling, how to tell when every control’s ‘IsValid’ property will have synchronized all to ‘true’, if that is even a good approach.


EDIT:

Okay, here is another way to ask the question. I have a List of something (in this case a list of an interface) and want to be able to respond to a public property change on each item in the list so I can take an action when all items are (bool in this case) true. The above explains the use case, but this is a more generic version of the question.


EDIT:

@Vincent “you might do it in an even simpler way with a custom “ValidatedChanged()” event that you can hook in the same way.”

It turns out that this is really what I was looking for. The property notification approach seems to be more for ease of use with data-bound controls. I read a lot of posts on this site about how to implement that but it really wasn’t what I wanted. I just wanted my objects to notify that an event occured, which happened to be a property change, but that is beside the point. I found documentation on implementing an event in an interface and I have it working now. Thanks for pointing me in the right direction and helping me realize what is really is that I needed.

  • 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-26T18:07:35+00:00Added an answer on May 26, 2026 at 6:07 pm

    So you have a ListBox which contains all your controls, and when all controls are validated, the Next button should be enabled ?
    If so, when one of your control validates, you might search all sons of the ListBox to check them for validation, using VisualTreeHelper.GetChildren to get them all.
    If you don’t want / can’t have a handle on the ListView, you might find it by searching up the visual tree starting from the control that just validated.
    Each ‘Validated’ event of each control would be handled by a ‘CheckIfAllValidated’ event handler, and when all are validated, you could raise a ‘AllValidated’ events that would be handled by the button (and maybe some other controls as well) to enable it.

    Edit : I understood that you did not want each component to know about their children, but notice that even the quite common PropertyChanged event has a ‘sender’ fields that tells who did raise the event. So any listener of a PropertyChanged on, say, the ‘validated’ property, can go up the visual tree, stop when it encounters a ListView, then search downstairs if all control that have a validated property do have this property set to true…

    Edit 2 :
    To be more clear about how to do it, either in your window new or on the window loaded event
    or maybe on the ContentRendered Event, depending on how your controls are loaded, you
    might use once that code to hook a handler to all your controls :

    For Each ThisControl In MainListView. 
       Dim ThisControlType = ThisControl.GetType
       Dim ThisControlPropertyChangedEvent = ThisControlType.GetEvent("PropertyChanged")
       ' you might wanna check here if event is not null / nothing
       ThisControlPropertyChangedEvent.AddEventHandler(ThisControl, New PropertyChangedEventHandler(AddressOf APropChanged))
     Next
    

    and you write the APropChanged somehow like that :

    Public Sub APropChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
    If e.PropertyName = "Validated" Then
        Dim ValidatedForAll = True
        For Each ThisControl In MainListView.Items
            Dim ThisControlType = ThisControl.GetType
            Dim ThisControlValidatedProperty = ThisControlType.GetProperty("Validated")
            'you might wanna check for non null here
            If Not ThisControlValidatedProperty.GetValue(ThisControl, Nothing) Then
               ValidatedForAll = False
               Exit For
            End If
        Next
        If ValidatedForAll Then
           MessageBox.Show("Yeeppee")    ' you might send an event instead.
        End If
    End If
    End Sub
    

    Edit 3 : you might do it in an even simpler way with a custom “ValidatedChanged()” event that you can hook in the same way.

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

Sidebar

Related Questions

I could not think of a better way to title this question. my apologies
Well I think the title of this question is far to be clear but
I apologize for the Title of this Question, but I couldn't think of a
The question title is probably a bit misleading, but I can't think of a
This is probably a very simple question, but at this time I have myself
i didn't really know how to title this question, but here's a thing that
Sorry for the slightly rubbish title. I could not think how to describe this
OK, I don't think the title says it right... but here goes: I have
Yes, this is probably yet another greatest-n-per-group question... But I've tried at least a
(The title for this question isn't the best, but I'm unsure how else to

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.