大佬教程收集整理的这篇文章主要介绍了silverlight / windows phone 7 selectedIndex列表框内按钮的问题,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<ListBox Name="listBox1"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding firstNamE}"/> <TextBlock Text="{Binding lastNamE}"/> <Button BorderThickness="0" Click="buttonPerson_Click"> <Image source="delete-icon.png"/> </Button> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
在我的代码隐藏中,我尝试抓取SELEctedIndex,这样我就可以从绑定到列表框的集合中删除该项.
private void buttonPerson_Click(object sender,RoutedEventArgs E) { // If SELEcted index is -1 (no SELEction) do nothing if (listBox1.SELEctedIndex == -1) return; myPersonList.removeAt(listBox1.SELEctedIndeX); }
但是,无论我在哪一行单击删除按钮,SELEctedIndex始终为-1
我错过了什么?
提前致谢!
<Button BorderThickness="0" Click="buttonPerson_Click" Tag="{Binding BindsDirectlyTosource=TruE}"> <Image source="delete-icon.png"/> </Button>
然后在事件处理程序中,您可以这样做:
private void buttonPerson_Click(object sender,RoutedEventArgs E) { myPersonList.remove((sender as Button).Tag); }
以上是大佬教程为你收集整理的silverlight / windows phone 7 selectedIndex列表框内按钮的问题全部内容,希望文章能够帮你解决silverlight / windows phone 7 selectedIndex列表框内按钮的问题所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。