我试图弄清楚当按下按钮时如何在我的 ListView 中删除选定的行。里面有一个带有多列的 GridView。这些列绑定到我创建的类中的字段,该类被发送到 ObservableCollection,后者填充我的 ListView 中的数据。
最好,在单击按钮后,整个选定的行都会有一条红线,尽管此时我什至会很高兴只敲击每个单元格的文本。
我尝试过各种各样的事情。我得到的最接近的是,我能够通过将预订类中的 Notes 字段更改为 TextBlock,然后添加这样的 TextDecoration 来获得工具提示以显示带有删除线的文本:
Reservation selected = (Reservation)shuttleView.SelectedItem;
TextDecoration td = new TextDecoration(TextDecorationLocation.Strikethrough, new Pen(Brushes.Black, 1), 0, TextDecorationUnit.FontRecommended, TextDecorationUnit.FontRecommended);
selected.Notes.TextDecorations.Add(td);
但是,这只会将装饰放在工具提示上,而不是在 ListView 中......
我在下面发布了我的列表视图和课程:
<ListView Height="287" HorizontalAlignment="Left" Margin="148,12,0,0" Name="shuttleView" VerticalAlignment="Top" Width="720" >
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="ToolTip" Value="{Binding Notes}" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Width="50" Header="Time"
DisplayMemberBinding="{Binding Time}" />
<GridViewColumn Width="50" Header="DO/PU"
DisplayMemberBinding="{Binding DropPickup}" />
<GridViewColumn Width="100" Header="# People"
DisplayMemberBinding="{Binding People}" />
<GridViewColumn Width="100" Header="Room #"
DisplayMemberBinding="{Binding Room}" />
<GridViewColumn Width="100" Header="Hotel"
DisplayMemberBinding="{Binding Hotel}" />
<GridViewColumn Width="112" Header="Location"
DisplayMemberBinding="{Binding Location}" />
<GridViewColumn Width="198" Header="Notes"
DisplayMemberBinding="{Binding Notes}" />
</GridView>
</ListView.View>
</ListView>
class Reservation
{
public string ResID { get; set; }
public string Time { get; set; }
public string DropPickup { get; set; }
public string People { get; set; }
public string Room { get; set; }
public string Hotel { get; set; }
public string Location { get; set; }
public string Notes { get; set; }
public Reservation(string ResID, string Time, string DropPickup, string People, string Room, string Hotel, string Location, string Notes)
{
this.ResID = ResID;
this.Time = Time;
this.DropPickup = DropPickup;
this.People = People;
this.Room = Room;
this.Hotel = Hotel;
this.Location = Location;
this.Notes = Notes;
}
}