tag 关闭时 无法获取到要关闭的标签
于是改写一下TagContainer
public class TagContainer1 : ItemsControl { public TagContainer1() { AddHandler(HandyControl.Controls.Tag.ClosedEvent, new RoutedEventHandler(Tag_OnClosed)); } public object CloseTag; private void Tag_OnClosed(object sender, RoutedEventArgs e) { if (e.OriginalSource is HandyControl.Controls.Tag Tag1) { CloseTag = null; var r = ShowMsgUtil.Question($"确定删除[{Tag1.Content}]吗?"); if (r != MessageBoxResult.Yes) return; Tag1.Hide(); CloseTag = Tag1.DataContext; if (ItemsSource == null) { Items.Remove(Tag1); } else { var item = ItemContainerGenerator.ItemFromContainer(Tag1); GetActualList()?.Remove(item); Items.Refresh(); } } } internal IList GetActualList() { IList list; if (ItemsSource != null) { list = ItemsSource as IList; } else { list = Items; } return list; } protected override DependencyObject GetContainerForItemOverride() => new HandyControl.Controls.Tag(); protected override bool IsItemItsOwnContainerOverride(object item) => item is HandyControl.Controls.Tag; }
标签:HandyControl,Tag1,item,list,Controls,TagContainer,Tag From: https://www.cnblogs.com/simadi/p/17749522.html