创建一个转换器以ID,并创建在Silverlight图像 [英] Creating a Converter to take an ID and create an Image in Silverlight
问题描述
我使用的是WCF气象服务和接收像ID,描述和图片天气信息。它返回这样的:
< WeatherDescription>
< WeatherID> 1 LT; / WeatherID>
<说明与GT;雷霆风暴< /说明>
< PictureURL>
http://ws.cdyne.com/WeatherWS/Images/thunderstorms.gif
< / PictureURL>
< / WeatherDescription>
现在在XAML我显示我的数据在DataGrid像这样:
< SDK:DataGridTextColumn标题=ID绑定={结合WeatherID}/>
以上绑定到返回7天的天气预报服务的另一个功能,但返回相同的天气ID随着天气的说明工作。我创建了所有的天气说明的阵列上的代码方面,像这样:
公共部分类的MainPage:用户控件
{
//天气描述
私人WeatherDescription数组[] weatherInformation;
WeatherSoapClient weatherClient =新WeatherSoapClient();
公众的MainPage()
{
的InitializeComponent();
weatherClient.GetWeatherInformationCompleted + =新的EventHandler< GetWeatherInformationCompletedEventArgs>(weatherClient_GetWeatherInformationCompleted);
weatherClient.GetWeatherInformationAsync();
}
无效weatherClient_GetWeatherInformationCompleted(对象发件人,GetWeatherInformationCompletedEventArgs E)
{
weatherInformation = e.Result;
}
}
-
什么我想要做的就是创建一个转换器,从该列取ID和使用天气的描述提供的URL将其转换为图像。
-
我知道Silverlight不支持GIF的,所以我想是的图像发送到将其转换为JPG的处理程序。
作为全新的既Silverlight和C#这些都是我真的有麻烦了两件事。感谢您的帮助提前!和代码片段是我最好的帮助,因为我不明白了很多的C#呢。
-
有关转换器,你可以做这样的事情:
< SDK:数据网格>
< SDK:DataGrid.Resources>
<局部:WeatherIdToImageConverter键=IdToImageConverter/>
< / SDK:DataGrid.Resources>
:
< SDK:DataGridTemplateColumn>
< SDK:CellTemplate>
<&DataTemplate的GT;
<图像来源={结合WeatherID,转换器= {StaticResource的IdToImageConverter}}/>
...
-
在您的实现转换器的,我会用ImageTools库( http://imagetools.codeplex.com/ ),以GIF和PNG之间的转换(PNG会质量优于JPEG)。
I am using a WCF weather service and receiving weather information like ID, Description, and Images. It returns like this:
<WeatherDescription>
<WeatherID>1</WeatherID>
<Description>Thunder Storms</Description>
<PictureURL>
http://ws.cdyne.com/WeatherWS/Images/thunderstorms.gif
</PictureURL>
</WeatherDescription>
Now in the XAML I am showing my data in a dataGrid as so:
<sdk:DataGridTextColumn Header="ID" Binding="{Binding WeatherID}" />
The above binding is to another function of the service that returns a 7 day forecast but returns the same weather ID that works with the weather description. I created an array of all the Weather Descriptions on the code side like so:
public partial class MainPage : UserControl
{
//array of weather descriptions
private WeatherDescription[] weatherInformation;
WeatherSoapClient weatherClient = new WeatherSoapClient();
public MainPage()
{
InitializeComponent();
weatherClient.GetWeatherInformationCompleted += new EventHandler<GetWeatherInformationCompletedEventArgs>(weatherClient_GetWeatherInformationCompleted);
weatherClient.GetWeatherInformationAsync();
}
void weatherClient_GetWeatherInformationCompleted(object sender, GetWeatherInformationCompletedEventArgs e)
{
weatherInformation = e.Result;
}
}
What I want to do is create a converter that takes the ID from that Column and converts it to an image using the URL supplied in the weather descriptions.
I know Silverlight does not support GIF's so I would like to send that image to a handler that would convert it to a JPG.
Being brand new to both Silverlight and C# these are two things that I am really having trouble with. Thank you for the help in advance! And code snippets are the best help for me since I do not understand a lot of C# yet.
For the converter, you can do something like this:
<sdk:DataGrid>
<sdk:DataGrid.Resources> <local:WeatherIdToImageConverter key="IdToImageConverter" /> </sdk:DataGrid.Resources> ... <sdk:DataGridTemplateColumn> <sdk:CellTemplate> <DataTemplate> <Image Source="{Binding WeatherID, Converter={StaticResource IdToImageConverter}}" /> ...
In your implementation of the converter, I would use the ImageTools library (http://imagetools.codeplex.com/) to convert between GIF and PNG (PNG will be better quality than JPEG).
这篇关于创建一个转换器以ID,并创建在Silverlight图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!