我在wpf canvas上有省略号我想选择多个省略号并删除特定的
选择Ellipse如何使用List<Ellipse>
我有删除逻辑的代码。
if (SelectedCanvasItem.VisualHit.GetType().BaseType == typeof(Shape))
{
var SelectedShapeTag = SelectedCanvasItem.VisualHit.GetValue(Shape.TagProperty);
if (SelectedCanvasItem != null)
{
//Ellipse SelectedHole = (Ellipse)SelectedShapeTag;
grdGrid.Children.Remove(SelectedCanvasItem.VisualHit as Shape);
//SetActivePattern(SelectedHole.ParentPattern);
//SelectedHoleSelectedHole.ParentPattern.CurrentHole = SelectedHole;
return; //Get out, we're done.
}
}
答案 0 :(得分:0)
如果我理解正确,那么:
1)您应该将VisualStates写入选定和未选择的项目 - 让用户了解选择了那些elipses。 2)在选择时,你可以创建一个列表列表ToDelete和用户准备就绪 - 删除它们
如果您只想在XAML中实现它,我认为它无法实现。
但是如果要逐个删除行为,则可以向每个椭圆添加行为 - 从表单或类似内容中删除。
C#:
List<string> Deletable_elipses
Elipse_Tap()
{
Elipse tappedElipse = sender as Elipse;
if (Deletable_elipses.Contains(tappedElipse.Name))
{
List.Remove(tappedElipse.Name); //Add if not in list to delete means that user unselected it
}
else
{
List.Add(tappedElipse.Name); //Add if not in list to delete means that user selected it
}
}
当你想要删除elipses:
foreach (string name in Deletable_elipses)
{
Elipse current = (Elipse)this.FindName(name);
current. //TODO logic to delete
}