Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to load a BitmapImage in MetroUI Dynamically
    text
    copied!<p>I've been experimenting with Windows 8 and Metro UI, I've written a perfectly reasonable load of a bitmap image, but it doesn't seem to be loading, any help is appreciated.</p> <pre><code>Public Sub New(Image As String) Debug.Print("ms-resource://MyAssembly/" &amp; Image) Img = New ImageBrush() Dim Bitmap As New BitmapImage() Bitmap.UriSource = New Uri("ms-resource://MyAssembly/" &amp; Image, UriKind.Absolute) Img.ImageSource = Bitmap Width = Bitmap.PixelWidth Height = Bitmap.PixelHeight Debug.Print("Height: " &amp; Height &amp; " Width: " &amp; Width) End Sub </code></pre> <p>In this example Width and Height always take values of zero. It is rendered in the same class..</p> <pre><code> Public Sub Render(X As Integer, Y As Integer, Canv As Canvas) Dim Sprite As New Shapes.Rectangle Sprite.Width = CDbl(Width) Sprite.Height = CDbl(Height) Sprite.Fill = Img Sprite.SetValue(Canvas.TopProperty, CDbl(Y)) Sprite.SetValue(Canvas.LeftProperty, CDbl(X)) Canv.Children.Add(Sprite) End Sub End Class </code></pre> <p>And here is where it is created/called:</p> <pre><code>V = New Sprite("Images/Test.bmp") gameRoot.Children.Clear() V.Render(100, 100, gameRoot) </code></pre> <p>===</p> <p>it isn't a problem with my canvas object, because if i fill it with <code>Sprite.Fill = New SolidColorBrush(Colors.White)</code> then it works fine, and I see a white square on my screen, the bitmap in question is set to "Copy Always", and is in the destination folder when i view it.</p> <p>I'm not quite sure what I'm doing wrong.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload