如果我使用的是包含库控件的散点图。用户可以将元素从库容器拖到分散视图。之后,用户可以删除图像。
我在视图框中创建了包含表面按钮和图像的样式作为拖动模板。
问题在于表面按钮的点击功能?我应该写什么来删除图像。
答案 0 :(得分:0)
是否要删除整个ScatterViewItem或仅删除图像并保留按钮? 通常,您可以通过使用此方法查找Visual Ancestor来删除ScatterViewItem:
/// <summary>
/// Attempts to get an ancestor of the passed-in element with the given type.
/// </summary>
/// <typeparam name="T">Type of ancestor to search for.</typeparam>
/// <param name="descendent">Element whose ancestor to find.</param>
/// <param name="ancestor">Returned ancestor or null if none found.</param>
/// <returns>True if found, false otherwise.</returns>
public static T GetVisualAncestor<T>(DependencyObject descendent) where T : class
{
T ancestor = null;
DependencyObject scan = descendent;
ancestor = null;
while (scan != null && ((ancestor = scan as T) == null))
{
scan = VisualTreeHelper.GetParent(scan);
}
return ancestor;
}
然后你可以从items集合中删除SVI:ancestor.items.remove(descendent);