Reputation: 13
If I am using scatter view that contains Library Controls. The user could drag element from the library container to scatter view. After that the user could remove the image.
I created style that contain surface button and image within view box as drag template.
The problem is with the click function of the surface button? what should i write to remove the image.
Upvotes: 0
Views: 382
Reputation: 1270
Do you want to remove the whole ScatterViewItem or just the image and keep the button? In general you remove ScatterViewItems by finding the Visual Ancestor with this method:
/// <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;
}
then you can remove the SVI from the items collection: ancestor.items.remove(descendent);
Upvotes: 0