我在win8中使用listview控件.我想在我按住项目时添加一个事件,然后删除该项目.
像这样的xaml和事件代码:
<ListView x:Name="ImageList" VerticalAlignment="Bottom" Background="LightGray" Width="1050" BorderBrush="Black" BorderThickness="2" Grid.Column="1" Holding="ListView_Hold1" SelectionChanged="OnSelectedChanged" SelectionMode="Single" Height="152" ScrollViewer.HorizontalScrollBarVisibility="Auto" ItemContainerStyle="{StaticResource ListViewItemStyle1}" Style="{StaticResource ListViewStyle1}"> <ListView.ItemTemplate> <DataTemplate> <Image Opacity="0.7" Width="150" Height="125" Stretch="UniformToFill" Source="{Binding}" /> </DataTemplate> </ListView.ItemTemplate> <ListView.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ListView.ItemsPanel> </ListView> private async void ListView_Hold1(object sender,Windows.UI.Xaml.Input.HoldingRoutedEventArgs e) {...}
似乎我无法从holdingroutdEventArgs获取任何信息,而是来自originalsource的属性.但它是图像,无法访问iteml
我找到了一个相对的问题:“如何在listview中获取被点击的项目”.它可以通过获取selecteditem的属性来解决.
有人可以帮帮我吗?给我一些线索.
在您的情况下,您应该能够从HoldingRoutedEventArgs.OriginalSource.DataContext中获取它:(假设ListView.ItemSource是ImageModel的列表)
原文链接:https://www.f2er.com/windows/363406.htmlprivate async void ListView_Hold1(object sender,Windows.UI.Xaml.Input.HoldingRoutedEventArgs args) { var source = (FrameworkElement)args.OriginalSource; var imageModel = (ImageModel)source.DataContext; }