I have a stack panel to which I want to add some icons dynamically.
If I add a TextBlock to the stack panel, it works fine:
let text = new TextBlock()
text.Text <- "Test"
stackPanel.Children.add(text)
However, my goal is to add an image, but it looks like it cannot resolve the image
let getImageSource(imagePath) =
let uri = new Uri(imagePath, UriKind.Relative)
new BitmapImage(uri);
let icon = new Image()
icon.Source <- getImageSource("images/fileIcon/icon.gif")
stackPanel.Children.Add(icon)
now when i do:
let icon = new Image()
icon.Source <- getImageSource("images/fileIcon/icon.gif")
stackPanel.Children.Add(icon)
let text = new TextBlock()
text.Text <- "Test"
stackPanel.Children.add(text)
I see there is an empty space between the texts, as if there was an empty image. Therefore, I assume that something is wrong with the way I resolve the path to the image, but I'm not sure why.
Thoughts?
Thank!
source
share