【发布时间】:2014-03-10 17:16:52
【问题描述】:
我想将图像源设置为资源中的图像。我有这个完美运行的 xaml:
<Image Source="/MyApplicationName;component/Resources/SplashScreen/InternetPlaceHolder.jpg" Height="577" Width="700" />
我想以在代码中加载图像的方式对其进行更改。所以我写了这段代码:
<Image Height="577" Width="700" x:Name="Image"/>
MyImage = new Image();
BitmapImage logo = new BitmapImage();
logo.BeginInit();
logo.UriSource = new Uri("pack://application:,,,/MyApplicationName;component/Resources/SplashScreen/InternetPlaceHolder.jpg");
logo.EndInit();
MyImage.Source = logo;
但它不起作用。
我检查过,徽标不是从资源图像初始化的。显然uri有问题。我用我找到的文档检查了它,它的格式似乎是正确的。
我的问题:URI 有什么问题?
【问题讨论】:
-
想一想:您是否尝试过使用带有
UriKind的重载Uri构造函数?您可以尝试指定UriKind.Absolute。不确定它是否会有所作为,但值得一试。 -
谢谢,已经测试过了,但是不行!
-
logo.UriSource = new Uri("/MyApplicationName;component/Resources/SplashScreen/InternetPlaceHolder.jpg", UriKind.RelativeOrAbsolute);-- 试试这个...