下面是我的XAML代码,我想使用SelectionChanged事件从ListView获取列表选择索引。我无法做到这一点。
<Page
x:Class="MMRevamp_2016.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MMRevamp_2016"
xmlns:ViewModels="using:MMRevamp_2016.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="Gray"
FontFamily="{StaticResource ContentControlThemeFontFamily}">
<Page.Resources>
<ViewModels:HomePageViewModel x:Key="ViewModel" />
<DataTemplate x:Key="headerTemplate">
<TextBlock Text="{Binding Title}" FontSize="16"/>
</DataTemplate>
<DataTemplate x:Key="pivotTemplate">
<ListView x:Name="listView" Background="White" SelectionChanged="getIndex" ItemsSource="{Binding Articles}" HorizontalAlignment="Left" Margin="-25 0 -25 0">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Tapped="ArticleDetailStackPanel_Tapped">
<Grid>
<Image x:Name="ArticleImage" Source="{Binding ImageURL}"></Image>
<Grid>
<Border VerticalAlignment="Bottom" Height="65" Background="Black" Opacity="0.5">
</Border>
<TextBlock x:Name="HeadLine" Text="{Binding HeadLine}" VerticalAlignment="Bottom"
Margin="10 0 0 5" TextWrapping="Wrap"
FontSize="20" Foreground="White"
Pivot.SlideInAnimationGroup="GroupTwo"
FontWeight="Bold" />
</Grid>
</Grid>
<StackPanel>
<TextBlock Text="{Binding Abstract}" TextWrapping="Wrap" FontSize="15"
Pivot.SlideInAnimationGroup="GroupTwo" Margin="10 5 0 10"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DataTemplate>
</Page.Resources>
<Grid Background="Gray">
<Grid x:Name="LoadingGrid" Visibility="Visible">
<ProgressRing x:Name="progressRing" IsActive="True" Foreground="White" HorizontalAlignment="Center" Width="60"
Height="50" VerticalAlignment="Center" Margin="0 20 0 0"></ProgressRing>
</Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="60"></RowDefinition>
<RowDefinition Height="45"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Image Source="Source" HorizontalAlignment="Center" Margin="1 5 0 0"></Image>
</Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Button x:Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content=""
Width="60" Height="60" Background="Transparent" Margin="-10 -20 0 0"
Click="HamburgerButton_Click"/>
</Grid>
<Grid Grid.Column="1">
<TextBlock Text="செய்திகள்" HorizontalAlignment="Center" FontSize="30"
Margin="-35 0 0 0" Foreground="White"></TextBlock>
</Grid>
</Grid>
<Grid Grid.Row="2" x:Name="ArticlesGrid" Visibility="Collapsed">
<SplitView x:Name="MySplitView" DisplayMode="CompactOverlay" IsPaneOpen="False"
CompactPaneLength="0" OpenPaneLength="220">
<SplitView.Pane>
<ListView x:Name="menuBindList" Background="Gray">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal" Tag="{Binding SectionName}">
<!--<Button x:Name="MenuButton1" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent" Margin="-10 0 0 0"/>-->
<TextBlock Text="{Binding TitleofAccess}"
Tag="{Binding SectionName}" FontSize="18"
VerticalAlignment="Center" Tapped="MenuTextBlock_Tapped" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</SplitView.Pane>
<SplitView.Content>
<ScrollViewer Name="articlesScroll">
<Pivot DataContext="{StaticResource ViewModel}" x:Name="pivot"
HeaderTemplate="{StaticResource headerTemplate}"
ItemTemplate="{StaticResource pivotTemplate}" ItemsSource="{Binding Feeds}" Margin="0,-10,0,10"
SelectionChanged="pivot_SelectionChanged">
</Pivot>
</ScrollViewer>
</SplitView.Content>
</SplitView>
</Grid>
</Grid>
</Grid>
</Page>
如果有人指导我实现这一目标会非常有帮助。提前致谢
答案 0 :(得分:0)
在getIndex方法中执行此操作,
int selectedItemIndex =(发送者为ListView).SelectedIndex;