Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我找不到图像不会显示在我创建的网格中的原因
Image img = new Image(); img.Source = new BitmapImage(new Uri(@"C:\logo.bmp", UriKind.Relative)); img.Width = 50; img.Height = 50; img.Margin = new Thickness(5, 5, 5, 5); grid1.Children.Add(img);
您的图像 URI 是绝对路径。
你应该写
img.Source = new BitmapImage(new Uri(@"C:\logo.bmp", UriKind.Absolute));
或更好
img.Source = new BitmapImage(new Uri(@"C:\logo.bmp"));