C# 如何在Windows应用商店应用程序的ListView/GridView中的单击项目处显示弹出/弹出
我正在使用Windows应用商店应用程序,希望显示有关在ListView或GridView中单击的项目的其他信息。此信息应显示在单击的项目旁边的弹出窗口或弹出按钮中(确实用C#定义,而不是用XAML定义) 问题是,ItemClick事件处理程序不提供有关单击的可视项的信息,只提供有关数据项的信息。因此,我没有关于在屏幕上显示弹出按钮或弹出按钮的位置的信息。使用附带的弹出按钮:C# 如何在Windows应用商店应用程序的ListView/GridView中的单击项目处显示弹出/弹出,c#,listview,windows-store-apps,flyout,C#,Listview,Windows Store Apps,Flyout,我正在使用Windows应用商店应用程序,希望显示有关在ListView或GridView中单击的项目的其他信息。此信息应显示在单击的项目旁边的弹出窗口或弹出按钮中(确实用C#定义,而不是用XAML定义) 问题是,ItemClick事件处理程序不提供有关单击的可视项的信息,只提供有关数据项的信息。因此,我没有关于在屏幕上显示弹出按钮或弹出按钮的位置的信息。使用附带的弹出按钮: <DataTemplate x:Key="ListItemTemplate"> <Grid R
<DataTemplate x:Key="ListItemTemplate">
<Grid RightTapped="ListRightTapped" Tapped="ListTapped" Background="Transparent">
<Grid>
...
</Grid>
<FlyoutBase.AttachedFlyout>
<Flyout Closed="listFlyout_Closed">
<StackPanel>
...
</StackPanel>
</Flyout>
</FlyoutBase.AttachedFlyout>
</Grid>
</DataTemplate>
您只需获取DataContext: 如果您有包含项目的列表:
MyList.ItemSource = new List<Item>();
var item是您要查找的内容我创建了一个解决方案,它的工作原理与旧的Windows Phone Toolkit ContextMenuService类似。菜单服务。你可以找到。使用该服务,无需在任何需要显示菜单的地方订阅事件处理程序 您的数据模板看起来像:
<StackPanel>
<local:MenuFlyoutService.MenuFlyout>
<MenuFlyout>
<!-- using the Click event -->
<MenuFlyoutItem Text="reply" Click="OnReplyClicked"/>
<!-- using commanding to DataContext of MenuItem -->
<MenuFlyoutItem Text="retweet" Command="{Binding RetweetCommand}"/>
<!-- using commanding to DataContext of parent list -->
<MenuFlyoutItem Text="favorite"
Command="{Binding DataContext.FavoriteCommand,
ElementName=TweetList}"
CommandParameter="{Binding}"/>
</MenuFlyout>
</local:MenuFlyoutService.MenuFlyout>
<!-- content for template goes here -->
</StackPanel>
从未使用过商店应用程序,但在win窗体上很容易,除了事件参数外,您是否还有发件人对象?此示例是MS应该在其文档页面上提供的。谢谢。我也想在我的应用程序中使用此功能。你能给我举个完整的例子吗。我尝试了上面的代码,但它不起作用。
<ListView x:Name="MyList">
<ListView.ItemTemplate>
<DataTemplate>
<Stackpanel>
<TextBox Text="{Binding Name}" />
<Button Content="Add sth" Click="AddClick" />
</Stackpanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
private void AddClick(sender, args){
var senderButton= (Button) sender;
var item = (Item) sender.DataContext; //Item form the list
}
<StackPanel>
<local:MenuFlyoutService.MenuFlyout>
<MenuFlyout>
<!-- using the Click event -->
<MenuFlyoutItem Text="reply" Click="OnReplyClicked"/>
<!-- using commanding to DataContext of MenuItem -->
<MenuFlyoutItem Text="retweet" Command="{Binding RetweetCommand}"/>
<!-- using commanding to DataContext of parent list -->
<MenuFlyoutItem Text="favorite"
Command="{Binding DataContext.FavoriteCommand,
ElementName=TweetList}"
CommandParameter="{Binding}"/>
</MenuFlyout>
</local:MenuFlyoutService.MenuFlyout>
<!-- content for template goes here -->
</StackPanel>