Q:

How to inform a UserControl that an event has occurred in another UserControl?

I have a Window called MainWindow which contains 2 UserControls:
SearchBox

and
CustomerList

When someone types into SearchBox I want to change CustomerList accordingly.
Question: What is the best way for CustomerList to know that the TextChanged event has been executed in SearchBox?
Right now I have SearchBox defined as:
public class SearchSubmittedEventArgs : EventArgs
{
    public string Term { get; set; }

    public SearchSubmittedEventArgs(string term)
    {
        Term = term;
    }
}

public partial class SearchBox : UserControl
{
    public event EventHandler<SearchSubmittedEventArgs> SearchSubmitted;
    public SearchBox()
    {
        InitializeComponent();
    }

    private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
    {
        if (SearchSubmitted != null) SearchSubmitted.Invoke(this, new SearchSubmittedEventArgs(((TextBox)sender).Text));
    }
}

and MainWindow has the following XAML and EventHandler:
<UserControls:SearchBox SearchSubmitted="SearchSubmitted_Invoked" />

private void SearchSubmitted_Invoked(object sender, SearchSubmittedEventArgs e)
{
    // I know SearchBox has been typed into

    // but I don't know how best to inform CustomerList
}

Do I need to pass the event from SearchSubmitted_Invoked to CustomerList? Is there a way for me to pass it directly from SearchBox to CustomerList?

A:

I think you can just subscribe to the event...Something along these lines:
 var search = new SearchBox();
 var cust = new CustomerList();
 search.SearchSubmitted += (s,e)=>{ cust.Update(e.Term); }

Hope it helps you find a way to move along...

