Ferry Meidianto | /* Living in .NET World */

CAT | Silverlight

It’s been few weeks after Silverlight 4 release. Now you can grab the final release Silverlight 4 Tools for Visual Studio 2010. That tool will also install the the final release of WCF RIA Services 1.0

If you have previously installed the tools, you don’t need to worry, it will uninstall them automatically.

· ·

Today when I was developing Silverlight app using Telerik RadControls, there was an error “Invalid FORMATETC structure” prevented me to complete the drag n drop of RadControls to the XAML editor.

I didn’t have any idea what was caused it because I could still drag n drop the Button control to the XAML. I thought it was Telerik but it could be anything.

Then the fast way to get the answer was of course Google.

Oops there are may results when I searched invalid FORMATETC, that’s a good sign to get the answer. Yeah it’s not Telerik specific error but Visual Studio error. It’s caused by the reference of toolbox items were messed up.

The solution was simply resetting the toolbox items by right clicking the toolbox then choosing Reset Toolbox.

Be patience, it could take sometime to reload all toolbox items.

· ·

Oct/09

13

Working with Image.Source on Silverlight 3

Below are some options to work with Image.Source

1. Embedded in the .xap file as Content

image

image

Note that the Build Action is “Content”

XAML

<Image x:Name="imgContent" Source="/Assets/Images/2.jpg" />

Code (C#)

imgContent.Source = new BitmapImage(new Uri("/Assets/Images/2.jpg", UriKind.Relative));

2. Embedded in the .xap file as Resource

image

image

Note that the Build Action is “Resource”

XAML

<Image x:Name="imgResource" Source="/SilverlightApplication1;component/Assets/Images/1.jpg" />

Code (C#)

imgResource.Source = new BitmapImage(new Uri("/SilverlightApplication1;component/Assets/Images/1.jpg", UriKind.Relative));

3. Absolute URL

The file is stored anywhere in the internet

XAML

<Image x:Name="imgAbsolute" Source="http://i3.silverlight.net/avatar/meidianto.jpg?cdn_id=10092009" />

Code (C#)

imgAbsolute.Source = new BitmapImage(new Uri("http://i3.silverlight.net/avatar/meidianto.jpg?cdn_id=10092009", UriKind.Absolute));

4. Stored inside the web application/website

Note: in this example the image is stored in the same folder as the .xap file

image

XAML

<Image x:Name="imgServer" Source="/3.jpg" />

Code (C#)

imgServer.Source = new BitmapImage(new Uri("/3.jpg", UriKind.Relative));

5. Async Network Call

Note: in this example the image is stored in the same folder as the .xap file as above

Code (C#)

private void LoadImage()
{
    WebClient client = new WebClient();
    client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
    client.OpenReadAsync(new Uri("3.jpg", UriKind.Relative));
}

void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    if (e.Error == null
        && e.Result != null)
    {
        BitmapImage img = new BitmapImage();
        img.SetSource(e.Result);

        imgServer.Source = img;
    }
}

· ·

Theme Design by devolux.nh2.me

Disclaimer

All postings/content on this blog are provided "AS IS" with no warranties, and confer no rights. All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer or sponsors. The content on this site is licensed under a Creative Commons Attribution By license.
To top