简体   繁体   中英

how to delete an item from a listBox in WP8

i have a list box view in windows phone that i want to delete an item from it upon a specified event .... how can i accomplish that this is my XAML code

 <ListBox x:Name="lstData2"
    ItemsSource="{Binding DataCollection2, Source={StaticResource PinsCollection}}" Grid.ColumnSpan="3" Foreground="#FF1D53D0" Height="583" VerticalAlignment="Bottom">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" Tap="StackPanel_Tap">
                <Image Margin="8"
                    VerticalAlignment="Top"
                    Source="{Binding ImageUri}"
                    Width="100"
                    Height="100" />
                <StackPanel Height="93" Width="259" >
                    <TextBlock Margin="8"
                        Width="250"

                        TextWrapping="Wrap"
                        VerticalAlignment="Top"
                        HorizontalAlignment="Left"
                        Foreground="#FF1D53D0"
                        Text="{Binding Pinnedname}"  Height="33" RenderTransformOrigin="0.5,0.5" FontFamily="Segoe WP SemiLight" FontSize="24" FontWeight="Bold" />
                    <TextBlock Width="155"
                        Margin="8,0,8,8"
                        VerticalAlignment="Top"
                        HorizontalAlignment="Left"
                        Text="{Binding Status}" Foreground="#FF1D53D0" FontFamily="Segoe WP SemiLight" />
                    <toolkit:ContextMenuService.ContextMenu>
                        <toolkit:ContextMenu>
                            <toolkit:MenuItem Header="Remove Pin" Click="RemovePin_Click" Tag="{Binding pinId}"/>

                        </toolkit:ContextMenu>
                    </toolkit:ContextMenuService.ContextMenu>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

You are using binding to show your data (DataCollection2) in a list view. Your list view is updated when your data is modified. To delete an item in the ListView, you should remove the corresponding item in the DataCollection2 and the list view will be automatically updated. Make sure that the DataCollection2 is an ObservableCollection instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM