3
votes

I have a LonglistSelector which displays a list a items, each item has a button:

My LongListSelector has a SelectionChanged event

private void MyLLS_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var item = (MyItemType)MyLLS.SelectedItem;
        // Job 1 goes here
    }

and each button in a item within LLS has a click event:

private void btDownload_Click(object sender, RoutedEventArgs e)
    {
        var button = (MyItemType)(sender as Button).DataContext;          
        // Job 2 goes here
    }

Problem is, when i click a button, it'll process the job 2, and after that it'll process Job 1. So how can I just do the job2 of click-button event?

1

1 Answers

1
votes

You should use a Boolean flag to determine it, just like:

bool isBtnClicked = false;

private void MyLLS_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    // check if button is clicked, if so, return and reset the isBtnClicked flag.
    if (isBtnClicked)
    {
        isBtnClicked = false;
        return;
    }
    var item = (MyItemType)MyLLS.SelectedItem;
    // Job 1 goes here
}

private void btDownload_Click(object sender, RoutedEventArgs e)
{
    var button = (MyItemType)(sender as Button).DataContext; 
    // set it true when button clicked
    isBtnClicked = true;         
    // Job 2 goes here
}