Image icon = null;
if (/* some logic test that succeeds*/)
{
icon = new Image();
icon.Width = 32;
icon.Height = 32;
icon.Stretch = Stretch.Fill;
icon.Source = new BitmapImage(new Uri("/Images/icons/flower.png", UriKind.Relative)); ;
icon.IsHitTestVisible = false;
}
if (icon != null)
MyCanvas.Children.Add(icon);
なぜこれが失敗するのかわかりません。プロジェクトの Images/Icons フォルダーに画像をコンテンツとして保存します。ソース (上記の .Source) を設定した後でも、ソースの PixelHeight と Width は 0 です。
誰かが理由を知っていますか?