0

如果我使用包含库控件的散点图。用户可以将元素从库容器中拖到分散视图中。之后,用户可以删除图像。

我在视图框中创建了包含表面按钮和图像的样式作为拖动模板。

问题出在表面按钮的点击功能上?我应该写什么来删除图像。

4

1 回答 1

0

你想删除整个 ScatterViewItem 还是只删除图像并保留按钮?通常,您可以通过使用以下方法查找 Visual Ancestor 来删除 ScatterViewItems:

/// <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;
    }

然后您可以从项目集合中删除 SVI:ancestrate.items.remove(descendent);

于 2012-07-31T07:50:21.070 回答