Category Archives: Silverlight

How to load a server side image in Silverlight Image control – another way to reduce XAP size

Direct references to images should be avoided in a Silverlight project as it makes the XAP file heavier. An alternative could be to have the images on server and load images by creating bitmap of the image by using the … Continue reading

Posted in ASP.NET, C#, Knowledge Sharing, Silverlight, Troubleshooting | Leave a comment

Using Images in Silverlight project = large XAP size

Using images in Silverlight project can cause serious problem of very large XAP size thus increased page load time. All images references in any Silverlight project are compiled and included into dll in XAP file. If you look inside XAP … Continue reading

Posted in Knowledge Sharing, Silverlight, Troubleshooting | Leave a comment

Silverlight – Application Library Caching

Caching assemblies at client can dramatically improve performance of a Silverlight application. When Application Library Caching is enabled for a Silverlight application, overall application startup improves as all third party assemblies/ DLLs are already on the client. In this case, … Continue reading

Posted in Knowledge Sharing, Silverlight, Troubleshooting | 4 Comments

Silverlight – C# – How to set a XAML element’s style from code behind

XAMLelementName.Style = Application.Current.Resources["Style"] as Style; // If your style is defined in App.xaml Application.Resources section XAMLelementName.Style = this.Resources[StyleKey] as Style; // if your style is defined in Page.XAML UserControl.Resources section XAMLelementName.Style = button.Resources[StyleKey] as Style; // if your style is … Continue reading

Posted in C#, Knowledge Sharing, Silverlight, Troubleshooting | 2 Comments

Silverlight – C# – How to set XAML element’s margin from code behind

XAMLelementName.Margin = new Thickness(1, 2, 3, 4); // OR, if you need uniform thickness XAMLelementName.Margin = new Thickness(5);

Posted in C#, Knowledge Sharing, Silverlight, Troubleshooting | 3 Comments

Download a file from server or open a web address in a pop-up window from Silverlight client

You can use HyperlinkButton control to do this. Example- <HyperlinkButton Name=”hplTemplete” Content=”Open Google in New Window” NavigateUri=”http://www.google.com” TargetName=”_blank” /> In case you need to set its NavigateUri from code behind, use following code- hplTemplete.NavigateUri =new Uri(“http://www.google.com”);

Posted in C#, Knowledge Sharing, Silverlight | 4 Comments

File Upload from Silverlight Client – A Generic http Handler to Upload File

From Silverlight client, you can upload files on server. For this you need a httphandler. Following is the code for the httphandler- using System; using System.Web; using System.IO; using System.Configuration; namespace WebProject.Web { public class FileUpload : IHttpHandler { public … Continue reading

Posted in C#, Knowledge Sharing, Silverlight | Leave a comment

Silverlight – Run Time Exception – Value does not fall within the expected range

If you are getting this error, you need to make sure that all xaml elements have unique names. Consider the following code snippets- for (int Count = 0; Count < StackPanel.Children.Count; Count++) { Chart ch = (Chart)StackPanel.Children[Count]; AnotherStackPanel.Children.Add(ch); } The … Continue reading

Posted in Knowledge Sharing, Silverlight, Troubleshooting | 2 Comments

How to associate XAP extension with Shell Zip application

To make it easier to unzip the XAP file of your application, you can associate the XAP extention with the Shell Zip application. To do this, run following command on command prompt- cmd /c assoc .xap=CompressedFolder

Posted in Knowledge Sharing, Silverlight, Troubleshooting | 4 Comments

Silverlight – What is inside a XAP file

XAP = dll(s) + AppManifest.xaml A XAP file is a combination of required DLLs and a AppManifest.xaml file compressed together and ZIP extention is changes to XAP. If you change the XAP extention back to ZIP, extract this ZIP file, … Continue reading

Posted in Knowledge Sharing, Silverlight, Troubleshooting | 5 Comments