我有一个绑定到xml文件的列表框。
<ListBox x:Name="listBox" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Hold="teacher_detail_Hold" Margin="0,12,0,12">
<TextBlock Text="{Binding Teacher}" Style="{StaticResource PhoneTextNormalStyle}" Grid.Row="0" Grid.ColumnSpan="2" HorizontalAlignment="Center"/>
<TextBlock Name="subjectName" Text="{Binding Subject}" Style="{StaticResource PhoneTextNormalStyle}" Grid.Row="1" Grid.ColumnSpan="2" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding Session}" Style="{StaticResource PhoneTextNormalStyle}" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left" />
<TextBlock Text="{Binding Group}" Style="{StaticResource PhoneTextNormalStyle}" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Right"/>
<Button Grid.Row="3" Content="delete" Click="delete_record"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
这是我的数据类
public class TimeTable
{
string teacher;
string subject;
string session;
string group;
string time;
//Teacher Property
public string Teacher
{
get { return teacher; }
set { teacher = value; }
}
//Subject Property
public string Subject
{
get { return subject; }
set { subject = value; }
}
//Session Propert
public string Session
{
get { return session; }
set { session = value; }
}
//Group Property
public string Group
{
get { return group; }
set { group = value; }
}
//Time Property
public string Time
{
get { return time; }
set { time = value; }
}
}
这是我正在使用的xml文件。
<Day id="Monday">
<subject sbjname="Software Testing" session="2010" group="Alpha" teacher="Tasawar Khan" classroom="Class Room 1" time="8:30">
</subject>
</Day>
<Day id="Tuesday">
<subject sbjname="Digital Image Processing" session="2011" group="Alpha" teacher="Ali Javed" classroom="Class Room 2" time="11:30">
</subject>
</Day>
我想按删除按钮删除条目。我想在 sbjname 属性的基础上删除数据。 这是删除按钮单击方法
private void delete_record(object sender, RoutedEventArgs e)
{
}
我知道如何从xml文件中删除。但我不知道如何从列表框中选择的项目中获取主题名称。
答案 0 :(得分:0)
YourDataClass item = listBox.SelectedItem as YourDataClass ;
YourdataList.Remove(item);