问题描述
|
首先,我说我已经尝试过并研究了它(这只是第一个问题)。这些是WPF的绝佳解决方案。众所周知,Windows Phone 7缺少一些不错的功能。
我的项目似乎注定没有动态图像。我有一个标签试图绑定到资源文件,但它不起作用。我已经尝试了以下两种方法,但似乎都没有用。
首先,广受欢迎的转换器。取得URI字符串并返回位图图像。显然,它可以在WPF中工作,但是我无法使其工作。
public class BitmapImageConverter : IValueConverter
{
public object Convert(object value,Type targettype,object parameter,CultureInfo culture)
{
try
{
return new BitmapImage(new Uri((string)value));
}
catch
{
return new BitmapImage();
}
}
public object ConvertBack(object value,CultureInfo culture)
{
throw new NotImplementedException();
}
}
然后是BitmapImage属性。真的没想到这个程序会奏效,也没有让您失望。
public BitmapImage ImgSource
{
get
{
// imgurI is a URI to the image.
BitmapImage newImg = new BitmapImage(new Uri(imgurI));
// Tried ALL the creation options. :(
//newImg.CreateOptions = BitmapCreateOptions.None;
return newImg;
}
}
这是我用于转换器(在其他地方定义)的XAML。
<Image Name=\"imgMap\"
VerticalAlignment=\"Center\"
HorizontalAlignment=\"Center\"
Source=\"{Binding imgurI,Mode=OneWay,Converter={StaticResource bitmapConverter}}\"
Stretch=\"None\"/>
我已经调试好它,以至于我知道每个绑定都返回了它应该返回的内容。转换器将被调用并执行我认为应该的操作。 imgurI始终返回格式为“” / MyNamespace; component / Images / MyImg.jpg \“的字符串,而ImgSource始终为bitmapImage。所有图像的BuildAction为\“ Resource \”。
我希望我缺少明显的东西。感谢您查看我的问题,如果需要更多信息,请发表评论。
解决方法
我怀疑这是您的问题,但请确保将
UriKind.Relative
传递给Uri
构造函数。
, 您应该使用“ 5”而不是“ 6”的Build Action。