【发布时间】:2017-03-13 14:46:30
【问题描述】:
我的问题:
我有一个 ListView,它有一个 ItemTemplate;包含一个带有一些 AppBarButtons 的 DataTemplate。
现在,当用户按下 ListView 中的按钮之一时,包含该按钮的 ListItem 不会突出显示。
这个问题也导致了我不知道怎么弄的问题
包含用户单击的按钮的列表项的索引。
列表项:
Mainpage.xaml中的代码:
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<!-- Simplified, Left out other AppBarButtons -->
<AppBarButton Foreground="White" VerticalAlignment="Center"
Label="Navigate" Icon="Map" >
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:InvokeCommandAction Command="{Binding Main.OpenMapCommand, Mode=OneWay, Source={StaticResource Locator}}"></core:InvokeCommandAction>
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</AppBarButton>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
命令:
public RelayCommand OpenMapCommand
{
get
{
return _openMapCommand
?? (_openPaneCommand = new RelayCommand(
() =>
{
Debug.WriteLine("Opening map");
// Center on New York City
var uriNewYork = new Uri(@"bingmaps:?cp=40.726966~-74.006076");
// Launch the Windows Maps app
var launcherOptions = new Windows.System.LauncherOptions();
launcherOptions.TargetApplicationPackageFamilyName = "Microsoft.WindowsMaps_8wekyb3d8bbwe";
var success = Windows.System.Launcher.LaunchUriAsync(uriNewYork, launcherOptions);
}));
}
}
这个问题需要提供什么答案:
- 如何获取包含 AppBarButton 的 ListItem 的索引,该 AppBarButton 已被按下以便在 relaycommand 中使用(请注意,当用户按下 AppBarButton 时,ListItem 不会被选中 )
【问题讨论】:
标签: c# xaml listview uwp mvvm-light