我有一个LonglistSelector,它显示一个项目列表,每个项目都有一个按钮:
我的LongListSelector有一个SelectionChanged事件
private void MyLLS_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var item = (MyItemType)MyLLS.SelectedItem;
// Job 1 goes here
}
并且LLS中的项目中的每个按钮都有一个点击事件:
private void btDownload_Click(object sender, RoutedEventArgs e)
{
var button = (MyItemType)(sender as Button).DataContext;
// Job 2 goes here
}
问题是,当我点击一个按钮时,它将处理作业2,之后它将处理作业1.那么我怎样才能完成点击按钮事件的工作2?
答案 0 :(得分:1)
您应该使用布尔标志来确定它,就像:
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
}