Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法获取网格或列表项中已单击项的索引_C#_Silverlight_Visual Studio 2010_Windows Phone 7_Listbox - Fatal编程技术网

C# 无法获取网格或列表项中已单击项的索引

C# 无法获取网格或列表项中已单击项的索引,c#,silverlight,visual-studio-2010,windows-phone-7,listbox,C#,Silverlight,Visual Studio 2010,Windows Phone 7,Listbox,我正在使用VS 2010 Express edition for windows phone处理windows phone 7。我使用wrappanel制作了图像网格。当我选择任何项目或图像时,我需要单击图像的id。同样,我还有一个列表框,当任何列表项目单击时,我再次需要单击文本块的值,即文本。 我正在使用此方法选择列表框项目,希望在此处输入id: private void on_selection(object sender, SelectionChangedEventArgs e) {

我正在使用VS 2010 Express edition for windows phone处理windows phone 7。我使用wrappanel制作了图像网格。当我选择任何项目或图像时,我需要单击图像的id。同样,我还有一个列表框,当任何列表项目单击时,我再次需要单击文本块的值,即文本。 我正在使用此方法选择列表框项目,希望在此处输入id:

private void on_selection(object sender, SelectionChangedEventArgs e)
{ 
   //want id of clicked item here
}

void grid_image_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
   //want id of clicked image in grid here
}
欢迎提出任何建议

listbox的xml是:

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="768"/>
        <RowDefinition Height="0*" />
    </Grid.RowDefinitions>


    <ListBox Name="Index_list" SelectionChanged="on_selection">

    </ListBox> 
    <Image Visibility="Collapsed" Margin="0,151,0,200" Name="selected_image"></Image>
</Grid>

您是否尝试过从事件args使用的
e.AddedItems
属性

正如医生所说,这将给你

自上次SelectionChanged事件发生以来选择的项目

具体来说,它将为您提供所选绑定对象的IList。这不会给你索引,但是一旦你有了所选的项目,如果你真的想要索引的话,就很容易得到索引(例如,你绑定到的索引)


您也可以将发件人强制转换为列表框,然后检查SelectedIndex,但列表框存在问题。

您是否尝试过使用事件参数的
e.AddedItems
属性

正如医生所说,这将给你

自上次SelectionChanged事件发生以来选择的项目

具体来说,它将为您提供所选绑定对象的IList。这不会给你索引,但是一旦你有了所选的项目,如果你真的想要索引的话,就很容易得到索引(例如,你绑定到的索引)


您也可以将发送者强制转换为列表框,然后检查所选索引,但列表框存在问题。

假设以下XAML:

<ListBox Name="Index_list" SelectionChanged="on_selection">
    <!-- These items could also be added in code -->
    <TextBlock Text="list box option 1" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 2" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 3" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 4" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 5" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 6" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 7" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 8" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 9" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 10" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 11" Style="{StaticResource PhoneTextExtraLargeStyle}" />
</ListBox>

假设以下XAML:

<ListBox Name="Index_list" SelectionChanged="on_selection">
    <!-- These items could also be added in code -->
    <TextBlock Text="list box option 1" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 2" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 3" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 4" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 5" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 6" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 7" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 8" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 9" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 10" Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="list box option 11" Style="{StaticResource PhoneTextExtraLargeStyle}" />
</ListBox>

thanx用于回复…但是e.AddedItems会给我什么?thanx用于回复…但是e.AddedItems会给我什么?wrappanel(来自工具箱)没有选定的事件,并且图像没有
ID
属性。您可以发布显示您正在尝试做什么的XAML吗?感谢您添加XAML,我已经提供了答案,但您仍然没有显示wrappanel,您所说的“id”(您是指索引)是什么意思,或者操纵事件处理程序连接到了什么。wrappanel(来自工具箱)没有选定的事件,并且图像没有
ID
属性。您可以发布显示您正在尝试做什么的XAML吗?感谢您添加XAML,我已经提供了答案,但您仍然没有显示包装,您所说的“id”(您是指索引)是什么意思或者操纵事件处理程序连接到什么。thanx对于你的回复Matt来说有很多。我实际上是将textblock作为项添加到列表中。每个textblock都有一些文本。我想,当单击列表的任何项时,我得到了被点击的textblock的文本。你能帮忙吗?谢谢你的回复Matt。我实际上是将textblock作为项目添加到列表中。每个textblock都有一些文本。我想,当点击列表的任何项目时,我得到被点击的textblock的文本。你能帮忙吗?