I am attempting to put together a small game engine, in Silverlight.
However, I am currently stuck on a rather lower level issue: The ability to draw images, in different positions. I intend on doing this dynamically through code, as, from what I’ve seen, most everything in XAML tends to be something that is at least somewhat static.
I have changed the base ‘grid’ into a Canvas, instead, so that I could draw anywhere on it. Perhaps this was a bad idea, though, I don’t know. Any or all advice would help.
InitializeComponent();
Image img = new Image();
img.Source = new BitmapImage(new Uri("Generic URL here"));
((BitmapImage)(img.Source)).DownloadProgress += new System.EventHandler<DownloadProgressEventArgs>(TestEventHandler);
Rect position = new Rect(new Point(25, 25), img.RenderSize);
LayoutRoot.Children.Add(img);
img.Arrange(position);
My original attempt, above, was to use the Arrange function, above, to ‘move’ the image to a new position. However, I have no idea how this works, and when I did the above code, the image no longer displayed on screen.
An unrelated question: is it possible to store images with the Silverlight application, as to not have them loaded via URL? I know it likely is, but what I really mean to ask, is how I would go about that?
Thank you all for any help.
-Stefan Zuefeldt
Use Canvas insteads of Grid is a good idea. Canvas is better than Grid in case you want to change position of its children controls
To move the image to a point p, you can do it by: