thakyZ
thakyZ

Reputation: 142

How to detect if an event is sent by an argument

I don't know if it is called an argument (i.e. textbox1.text = "Hello";).

I have a control and there is a text box in it. It has a dropdown box that opens when the text is changed. But when I update the text in the text box that box drops down.

I need a way to make it so it only drops down if someone manually does it.

TBAddressBar.ABText.Text = getCurrentBrowser().Source.ToString();

and

    public void ABText_TextChanged(object sender, TextChangedEventArgs e)
    {
        if (sender == 1*)
        {
            ABDropDown.Visibility = Visibility.Visible;
        }
        else
        {
            ABDropDown.Visibility = Visibility.Collapsed;
        }
    }

Upvotes: 0

Views: 113

Answers (3)

nawfal
nawfal

Reputation: 73173

Simple, just remove the code from your TextChanged Event.

Anyway you got the basic idea.. Now do your dropdown logic in KeyPress event, since it accepts only characters and not the modifiers. So it behaves closer to your requirement. Not that you cant handle the same using KeyDown and KeyUp, you can, but more code..

Upvotes: 0

Mark Hall
Mark Hall

Reputation: 54532

What I have done in the past is use a boolean variable that I set when I update my textboxes programically to bypass the TextChangedEvent.

i.e.

bool loading;

....

loading =true;

TBAddressBar.ABText.Text = getCurrentBrowser().Source.ToString(); 

loading = false;

public void ABText_TextChanged(object sender, TextChangedEventArgs e) 
{ 
    if(loading) return;
    ....
} 

Upvotes: 1

bobbymcr
bobbymcr

Reputation: 24167

If someone manually does it, presumably they are using keypresses to do so. In that case, use KeyDown or KeyUp events to show the dropdown instead.

Upvotes: 1

Related Questions