Istview Removal of items

Source: Internet
Author: User

As the title says, is to delete the ListView binding item function; In view of this feature did spend a lot of time, and the Internet can not find the need to delete the case, so, I did a case, only for the predecessors and peers for reference, if there is inappropriate, but also hope that the guidance, I will again put the excitation, Below to get to the chase:

According to the requirements we are required to implement the function: Click Delete, the entire items to remove, initially with the ListView. Items.removeat (Listview.selectedindex) Such a way to delete, debugging when the report "catastrophic ..." error, helpless I can only try to Listview. Items.remove (Listview.selecteditems) and the Listview. Items.remove (Listview.selecteditem[0]) and so on, are not, not to report a catastrophic error, is no effect, then the head really hurts, the internet to find information, no want, only to ask the big God in the group, The idea and coding level of the great God really got me out of the way, but even if the code written by the great God doesn't do what I want, I have to continue to think of ways to learn from the other ways of C #, and if it's the UWP that's going to be a little different than C # in the UWP and the C # before Microsoft, so I Then finally thought, I directly manipulate the binding of the notification list is not OK, the operation is finished and then re-bound once the good Ah,

So, the function is realized, the following shows the detailed code:

1<listview x:name="ListView"grid.row="2" 2Horizontalalignment="Center" 3margin="0"Verticalalignment="Center">4<ListView.Resources>5<style targettype="ListViewItem">6<setter property="Padding"Value="0"></Setter>7<setter property="horizontalcontentalignment"Value="Stretch"></Setter>8<setter property="Template">9<Setter.Value>Ten<controltemplate targettype="ListViewItem"> One<grid background="{TemplateBinding Background}"> A<ContentPresenter -Content="{TemplateBinding Content}" -margin="{TemplateBinding Padding}"/> the</Grid> -</ControlTemplate> -</Setter.Value> -</Setter> +</Style> -</ListView.Resources> +<ListView.ItemTemplate> A<DataTemplate> at<relativepanel minwidth=" the"  -minheight=" -" -cornerradius="3" -margin="5" -Borderbrush="Green"  -borderthickness="1"> in<textblock name="Tbname"Relativepanel.alignleftwithpanel="True" -text="{Binding name}"></TextBlock> to<textblock relativepanel.below="Tbname"margin="0,5,0,0" +text="{Binding Sex}"></TextBlock> -<textblock name="Tbdelitem"Verticalalignment="Center"Relativepanel.alignrightwithpanel="True" theFontsize=" -"text="& #xE106;"fontfamily="{StaticResource symbolthemefontfamily}" *Foreground="Red"Tapped="tbdelitem_tapped" $Relativepanel.alignverticalcenterwithpanel="True"></TextBlock>Panax Notoginseng</RelativePanel> -</DataTemplate> the</ListView.ItemTemplate> +</ListView>

The background is also added to:

1  Public Sealed Partial classMainpage:page2     {3Observablecollection<info> OC {Get;Set; } =NewObservablecollection<info>();4          PublicMainPage ()5         {6              This. InitializeComponent ();7         }8         9         protected Override voidonnavigatedto (NavigationEventArgs e)Ten         { One              A              -              This. DataContext = This; -              for(inti =0; I <Ten; i++) the             { -Oc. ADD (NewInfo () {name="Zhang San"+i, sex="male"+i}); -             } -Listview.itemssource =OC; +         } -  +         Private voidTbdelitem_tapped (Objectsender, Tappedroutedeventargs e) A         { at             //when I click on the target object, the object's entire bound object is already selected. -             //then, remove the corresponding object from the notification list observablecollection<info> -INFO fn = Listview.selecteditem asInfo; - OC. Remove (FN); -Listview.itemssource =OC; -         } in     } -  to      Public classInfo +     { -          Public stringName {Get;Set; } the          Public stringSex {Get;Set; } *          Public stringHobby {Get;Set; } $         Panax Notoginseng}
View Code

The code is attached, so end it, if you have any questions to contact, qq:1358338055

Istview Removal of items

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.