The istView item is removed. The istView item is removed.
As the title says, it is used to delete the ListView bind item. Since this function did take a lot of time and the cases required for deletion were not found online, I made a case for reference only by my predecessors and colleagues. If you have any mistakes, I hope you can give me some advice. I will continue to work on the subject:
As required, we need to implement the function: When you click Delete, remove the entire Items and use listview. items. removeAt (Listview. selectedIndex ...... "error, but I can only try listview. items. remove (Listview. selectedItems) and listview. items. remove (Listview. selectedItem [0, I can only ask the great gods in the group, but the idea and coding level of the great gods do not make me feel overwhelmed. However, even the code written by the great gods cannot implement the functions I want, so I have to continue to find a solution, for reference to other methods of c #, if you are developing uwp, you will know that writing uwp C # is somewhat different from Microsoft's previous C #, so I can only continue to try it, later, I finally thought that it would be okay to directly operate on the bound notification list. After the operation is complete, I can re-bind it again,
As a result, the function is implemented. The detailed code is shown below:
1 <ListView x:Name="listView" Grid.Row="2" 2 HorizontalAlignment="Center" 3 Margin="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>10 <ControlTemplate TargetType="ListViewItem">11 <Grid Background="{TemplateBinding Background}">12 <ContentPresenter13 Content="{TemplateBinding Content}"14 Margin="{TemplateBinding Padding}" />15 </Grid>16 </ControlTemplate>17 </Setter.Value>18 </Setter>19 </Style>20 </ListView.Resources>21 <ListView.ItemTemplate>22 <DataTemplate>23 <RelativePanel MinWidth="330" 24 MinHeight="50"25 CornerRadius="3"26 Margin="5"27 BorderBrush="Green" 28 BorderThickness="1">29 <TextBlock Name="tbName" RelativePanel.AlignLeftWithPanel="True"30 Text="{Binding name}"></TextBlock>31 <TextBlock RelativePanel.Below="tbName" Margin="0,5,0,0"32 Text="{Binding sex}"></TextBlock>33 <TextBlock Name="tbDelItem" VerticalAlignment="Center" RelativePanel.AlignRightWithPanel="True"34 FontSize="18" Text="" FontFamily="{StaticResource SymbolThemeFontFamily}"35 Foreground="Red" Tapped="tbDelItem_Tapped"36 RelativePanel.AlignVerticalCenterWithPanel="True"></TextBlock>37 </RelativePanel>38 </DataTemplate>39 </ListView.ItemTemplate>40 </ListView>
The background is also added:
1 public sealed partial class MainPage: Page 2 {3 ObservableCollection <Info> oc {get; set ;}= new ObservableCollection <Info> (); 4 public MainPage () 5 {6 this. initializeComponent (); 7} 8 9 protected override void OnNavigatedTo (NavigationEventArgs e) 10 {11 12 13 this. dataContext = this; 14 for (int I = 0; I <10; I ++) 15 {16 oc. add (new Info () {name = "Michael" + I, sex = "male" + I}); 17} 18 listView. itemsSource = oc; 19} 20 21 private void tbDelItem_Tapped (object sender, TappedRoutedEventArgs e) 22 {23 // when I click the target object, you have selected the entire bound object of the object, 24 // and then removed the corresponding object 25 Info fn = listView in the notification list ObservableCollection <Info>. selectedItem as Info; 26 oc. remove (fn); 27 listView. itemsSource = oc; 28} 29} 30 31 public class Info32 {33 public string name {get; set;} 34 public string sex {get; set ;} 35 public string holobby {get; set;} 36 37}
View Code
The Code has been attached, so it will end. If you have any questions, contact qq: 1358338055.