首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Windows Mobile >

怎么定位ListView中的Item

2013-04-26 
如何定位ListView中的Item?局部的xmal代码:ListView x:NameListView_SongList Padding55,0,10,0Ite

如何定位ListView中的Item?
局部的xmal代码:


<ListView x:Name="ListView_SongList" Padding="55,0,10,0"
                          ItemContainerStyle="{StaticResource RecommendItemContainerStyle}" IsItemClickEnabled="True" ItemClick="ListView_SongList_ItemClick" SelectionChanged="ListView_SelectionChanged">
                            <ListView.ItemTemplate>
                                <DataTemplate ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto">
                                    <Grid Width="1000" Height="40">
                                        <Grid Grid.ColumnSpan="4" Background="White" Opacity="0.1"/>
                                        <Grid Height="36" Margin="10,6,0,0">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition/>
                                                <ColumnDefinition Width="0.7*"/>
                                                <ColumnDefinition Width="0.6*"/>
                                                <ColumnDefinition Width="0.5*"/>
                                            </Grid.ColumnDefinitions>
                                            <TextBlock x:Name="FileName_TextBlock" Grid.Column="0" Text="{Binding FileName}" Style="{StaticResource ListViewTextStyle}" />


                                            <TextBlock Grid.Column="1" Text="{Binding Artist}" Style="{StaticResource ListViewTextStyle}" />
                                            <TextBlock Grid.Column="2" Text="{Binding Ablum}" Style="{StaticResource ListViewTextStyle}"/>
                                            <StackPanel Grid.Column="3" Orientation="Horizontal">
                                                <Button Style="{StaticResource ListViewImageButtonStyle}">
                                                    <Image Source="Images/ListPage/ListAddTo.png" Style="{StaticResource ListViewImageStyle}"/>
                                                </Button>
                                                <Button Style="{StaticResource ListViewImageButtonStyle}">
                                                    <Image Source="Images/ListPage/FavoriteList.png" Style="{StaticResource ListViewImageStyle}"/>
                                                </Button>
                                                <Button Style="{StaticResource ListViewImageButtonStyle}" Click="DeleteButton_Click">
                                                    <Image Source="Images/ListPage/ListDelete.png" Style="{StaticResource ListViewImageStyle}"/>


                                                </Button>
                                            </StackPanel>
                                        </Grid>
                                    </Grid>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>



实现的ListView的UI:
怎么定位ListView中的Item

我想点击每行的Item中的删除、添加按钮后可以获取该Item,请问该怎么实现呢? Windows8 listview
[解决办法]
findname(x:Name)
[解决办法]
FrameworkElement currentElement = (FrameworkElement)sender;
Object itemData = currentElement.DataContext;

itemData就是当前数据项

ListBoxItem listBoxItem = this.gridViewRSSItems.ItemContainerGenerator.ContainerFromItem(itemData) as ListBoxItem;

获取当前UI容器元素

热点排行