Delete Image object on top of screen, Screen contains a Canvas, two images at any point on canvas in wp7/Silverlight
I wish to delete / modify_the_source the image on top of a screen in wp7 / Silverlight. The screen contains 1. A canvas, 2. Stack of several images on top of Canvas. There are multiple images that spans the canvas. So, the images, on canvas, are like layers of 2D array of images. Given is the Point(Any coordinate). Accessing image objects is the problem here.
I tried using VisualTreeHelper.FindElementsInHostCoordinates(tempFinal, canvasMain)
to get the collection but it's not returning any Image.
Your help will be whole heartedly thanked.
my Code snippet to modify the image object is below:
IEnumerable<UIElement> uiElementCollection = VisualTreeHelper.FindElementsInHostCoordinates(tempFinal, canvasMain);
if (null == uiElementCollection)
{
return;
}
foreach (UIElement uiElement开发者_如何转开发 in uiElementCollection)
{
if (uiElement is Image)
{
Image image = uiElement as Image;
if (null != image)
{
BitmapImage image1 = new BitmapImage();
image1.UriSource = new Uri("BackGround_Ball.jpg", UriKind.RelativeOrAbsolute);
image.Source = image1;
}
}
}
You should try to find your images in Canvas.Children. Just use this istead of "VisualTreeHelper.FindElementsInHostCoordinates(tempFinal, canvasMain);" Canvas.Children is a collection of UIElement. Read here for information about this collection. http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.children.aspx
精彩评论