单击LongListSelector Windows phone 8中的一个按钮
本文关键字:一个 按钮 Windows LongListSelector phone 单击 | 更新日期: 2023-09-27 18:19:28
我有一个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。那么我如何才能完成点击按钮事件的job2呢?
您应该使用布尔标志来确定它,就像:
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
}