Windows phone 7 windows phone 8创建自定义静态资源
我有一个网格,在这个网格中有几个图像和一些其他元素。我想创建一个背景图像作为每个图像的静态资源。我知道这不是不可能的,所以请帮助我。 例如(这不是正确的代码,这只是我想要实现的示例Windows phone 7 windows phone 8创建自定义静态资源,windows-phone-7,windows-phone-8,windows-phone,Windows Phone 7,Windows Phone 8,Windows Phone,我有一个网格,在这个网格中有几个图像和一些其他元素。我想创建一个背景图像作为每个图像的静态资源。我知道这不是不可能的,所以请帮助我。 例如(这不是正确的代码,这只是我想要实现的示例 <style x:key="myimage"> <Setter property="Image" value="images/loading.png"/> </style> <image style={staticresource myimage" source={bind
<style x:key="myimage">
<Setter property="Image" value="images/loading.png"/>
</style>
<image style={staticresource myimage" source={binding someotherimage"/>
我还不明白这个问题,但也许你可以试试这样的方法:(这是一个例子) XAML 将其放入PhoneApplicationPage:
xmlns:my="clr-namespace:YOURNAMESPACE"
<phone:PhoneApplicationPage.Resources>
<my:BinaryToImageSourceConverter x:Key="BinaryToImageSourceConverter1" />
</phone:PhoneApplicationPage.Resources>
<Image Source="{Binding Path=Image, Converter={StaticResource BinaryToImageSourceConverter1}, ConverterParameter=Image, TargetNullValue='/Image/no-foto-60.png'}" Stretch="None" />
namespace YOURNAMESPACE
{
public class BinaryToImageSourceConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null && value is byte[])
{
try
{
var bytes = value as byte[];
var stream = new MemoryStream(bytes);
var image = new BitmapImage();
image.SetSource(stream);
stream.Close();
return image;
}
catch (Exception)
{ }
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}