【发布时间】:2010-12-30 05:03:42
【问题描述】:
你好 有没有办法在 ListBox 的 x:Array 中获取按钮的索引。
我知道我可以在单击后获取按钮信息(通过 sender 参数),但我无法获取它的索引。
ListBox.CurrentItem 和 ListBox.SelectedItem 不起作用
运气不好 int t = this.lstButtons.SelectedIndex;
t=this.lstButtons.Items.CurrentPosition;
t=lstButtons.ItemContainerGenerator.IndexFromContainer((Button)sender);
<x:Array Type="Button" >
<Button Content="Button1" VerticalAlignment="Top" Width="149" Click="Button_Click" />
<Button Content="Button2" VerticalAlignment="Top" Width="149" Click="Button_Click"/>
<Button Content="Button3" BorderThickness="4" VerticalAlignment="Top" Width="149" Click="Button_Click"/>
</x:Array>
</ListBox.ItemsSource>
【问题讨论】:
-
感谢您的指针 var bouts = lstButtons.ItemsSource.Cast
标签: wpf arrays button listbox indexing