[英]How to get Image and text from RSS file in WP7?
I am trying to get RSS text with its Image but image couldn't show i would view model for getting image and use simple RSS technique to get image would you tell me how to get both image and text....... Here is my XAML code: 我正在尝试获取带有其图像的RSS文本,但是图像无法显示,我将查看模型以获取图像,并使用简单的RSS技术获取图像,如果您告诉我如何同时获取图像和文本,则为……。是我的XAML代码:
<ListBox Name="lstRSS" ItemsSource="{Binding FeedItems}" DataContext="{StaticResource MainViewModel}" FontSize="30" Grid.Row="1">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="700">
<TextBlock Text="{Binding Path=Title}"></TextBlock>
<UserControls:Loader Width="100" Height="100" />
<Image Source="{Binding Link}" Width="450" Height="350" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
You cannot bind to a URL in that way as a String/Uri is not a valid value for the Image.Source property. 您不能以这种方式绑定到URL,因为String / Uri对于Image.Source属性不是有效值。 If a constant URL is set in xaml then the image will be shown correctly as the compiler generated code takes the URL and converts it to a BitmapSource.
如果在xaml中设置了恒定的URL,则在编译器生成的代码采用该URL并将其转换为BitmapSource时,该图像将正确显示。
To bind an image URL in that fashion you will need a converter . 要以这种方式绑定图像URL,您将需要一个转换器 。 The converter can take the URL and convert it to a BitmapImage:
转换器可以获取URL并将其转换为BitmapImage:
public class UriToImageConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// This could be extended to accept a Uri as well
string url = value as string;
if (!string.IsNullOrEmpty(url))
{
return new BitmapImage(new Uri(url, UriKind.RelativeOrAbsolute));
}
else
{
return null;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
You then need to add an instance of this class to the apps resources (in app.xaml or in the page xaml): 然后,您需要将此类的实例添加到apps资源(在app.xaml或xaml页面中):
<local:UriToImageConverter x:Key="ImageConverter"/>
You can then set the binding like this: 然后可以像这样设置绑定:
<Image Source="{Binding Link, Converter={StaticResource ImageConverter}}" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.