从列表框中删除自定义项 [英] delete custom items from listbox
本文介绍了从列表框中删除自定义项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含自定义项目,文本块和复选框的列表框:
i have a listbox with custom items, textblock and checkbox:
<UserControl x:Class="kashtat.Listboxitems"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}" Height="62" Width="284">
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
<TextBlock x:Name="title" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="202" Height="42"/>
<CheckBox x:Name="condetion" Content="" HorizontalAlignment="Left" Margin="217,-9,-39,-31" VerticalAlignment="Top" Width="100" Height="90"/>
</Grid>
</UserControl>
我有这个代码用于添加itmes(locationslistboxedit是列表框的名称):
and i have this code for adding itmes (locationslistboxedit is the name of the listbox):
For t = 1 To 1000
If locations(t, 0) <> "" Then
Dim costumlistboxitem As Listboxitems = New Listboxitems
costumlistboxitem.condetion.IsChecked = False
costumlistboxitem.title.Text = locations(t, 0)
locationslistboxedit.Items.Add(costumlistboxitem)
End If
Next
i想要删除被检查的项目。我该怎么做?
i want to delete the items which is checked. how can i do that?
推荐答案
尝试CheckBox控件或ListBox的DataContext属性。 SelectedItem属性获取所选CheckBox的ListBoxItems控件。
Try DataContext property of CheckBox control or ListBox.SelectedItem property to get ListBoxItems control for selected CheckBox.
Dim result as ListBoxItems = CType(sender, CheckBox).DataContext
locationslistboxedit.Items.Remove(result)
这篇关于从列表框中删除自定义项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文