Sunday, September 12, 2010

Charts in Silverlight

I have been searching for a different types of charts in silverlight .I found a open source control called Visifire that supports WPF and Silverlight with the option of 3D View.
Here is the link to draw the chart control.

Wcf Data Service

I have created a basic WCF Dataservices using entity framework in silverlight. When i about to create method and access it i m getting error as bad request,Error in query syntax.

I have created Wcf Dataservice as
public static void InitializeService(IDataServiceConfiguration config)
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);

config.UseVerboseErrors = true;

public string GetUsers(string userId)
return "my data";

my browser uri is

And here is the Code from Client:
public void LoadData(string userId)
var qry = ctx.CreateQuery("GetUsers").AddQueryOption("UserId", string.Format(@"'{0}'", userId));

qry.BeginExecute(new AsyncCallback(OnLoadComplete), qry);

When i execute via browser uri i m getting the result. Not by accessing via method in SL.
I found in SL it adds () in browser URI as like this

After a long search we can execute the method as mentioned below which solve me the problem.

ctx.BeginExecute(new Uri(string.Format("{0}GetUsers?UserId={1}", smileEntites.BaseUri, "'1' "), UriKind.RelativeOrAbsolute), OnLoadComplete, null);

void OnLoadComplete(IAsyncResult result)

// Get the results and add them to the collection
IQueryable queryResults = smileEntites.EndExecute(result).AsQueryable();
foreach (var coursw in queryResults)

catch (Exception ex)
if (HtmlPage.IsEnabled)
HtmlPage.Window.Alert("Failed to retrieve data: " + ex.ToString());

Wednesday, April 21, 2010

Bypassing the Image Cache

By default Silverlight will not download an image more than once if is contained within the image cache. That is, as long as the URI remains the same it will reference the image from the cache.
So what if the image changed on the server even though it has the same URI? Your application can force an update by setting the property IgnoreImageCache to true.
Image img = new Image();

Uri uri = new Uri("", UriKind.Absolute);
BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage(uri);
bi.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
img.Source = bi;

Monday, November 30, 2009

Paging in wrapPanel

Here is the paging Functionality in Wrap Panel
I have added Wrap panel using the namespace as shown in the image

Do not set width on wrap panel. Wrap panel loads image based on main page size changes
I have loaded images from xml and when the main window is resized paging changes based on that

public MainPage()
this.SizeChanged += new SizeChangedEventHandler(MainPage_SizeChanged);
webClient = new WebClient();
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
webClient.OpenReadAsync(new Uri("Application.xml", UriKind.RelativeOrAbsolute));
this.Loaded += new RoutedEventHandler(MainPage_Loaded);

void MainPage_SizeChanged(object sender, SizeChangedEventArgs e)
private void Paging()
appHeight = this.ActualHeight;
appWidth = this.ActualWidth;
pageSize = Convert.ToInt32(Math.Floor(((this.ActualHeight) - 216) / 38));
if (pageSize != 0.0)
pagecount = Convert.ToInt32(Math.Ceiling(totalSize / pageSize));
if (pagecount != 1)
for (int i = 0; i <= pagecount; i++) {
HyperlinkButton href = new HyperlinkButton();
href.Content = i + 1;
href.Click += new RoutedEventHandler(href_Click);

void href_Click(object sender, RoutedEventArgs e)
HyperlinkButton hf = sender as HyperlinkButton; GetInteractivity(Convert.ToInt32(hf.Content));
void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
xmlParser = new XMLParser(e.Result);
BindXML(); webClient.OpenReadCompleted -= new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
totalSize = interactivityList.Count; Paging();
catch (Exception ex) { }
private void GetInteractivity(double pgSize)
int startVal = Convert.ToInt32((pgSize - 1) * pageSize);
int endVal = Convert.ToInt32((pgSize) * pageSize);
endVal = endVal > Convert.ToInt32(totalSize) ? Convert.ToInt32(totalSize) : endVal;
for (int i = startVal; i <=endVal;i++)

Image img = new Image();
img.Width = 160;
img.Height = 160;
string imgpath = interactivityList[i].imagePath.ToString();
Uri uri = new Uri(imgpath, UriKind.Relative);
ImageSource src = new BitmapImage(uri);
img.Source = src;
img.Tag = interactivityList[i].xapfilePath;
img.MouseLeftButtonDown += new MouseButtonEventHandler(image1_MouseLeftButtonDown);
Rectangle rect = new Rectangle();
rect.Width = 100;
rect.Height = 100;
private void BindXML()
List elements = xmlParser.GetElements("Application");
if (elements.Count > 0)
for (int i = 0; i <= elements.Count; i++)

Interactivity interactivity = new Interactivity();
imageElement = elements[i].Element("ImagePath");
interactivity.imagePath = imageElement.Value.ToString();
xapElement = elements[i].Element("xapFilePath");
interactivity.xapfilePath = xapElement.Value.ToString();
} public class Interactivity
public string imagePath { get; set; }
public string xapfilePath { get; set; }


Replace <= with <

LoadXap File Dynamically through HTML page

How to load xap file dynamically in silverlight?
We can use xap loader class method or else u can load xap file via html Page.Here is my example to load the xap file dynamically
Lets Create a sample application and bind the image in tat application .I have created the project in the name of sampleapplication .

Now i have created the other project name loadXAP to load sampleapplication XAP file.I have added MyPage.htm Page in the web project,and add the following code as in the image

and add div with the Id 'silverlightControlHost' in the body tag .Now place the sample application Xap file in the ClientBin folder of loadXap Application.Now i have place thumbnail of image and when i click on the image it redirects to MyPage.htm file with the XAP filename as Query string .Here is the screen shot of the application

Thursday, October 22, 2009

Accordian Control Problem in Blend

Hi ,
When the Accordian Control is added in silverlight. When you open in Blend You could not able to find the control in Expression Blend.

To View in the Blend You should add reference System.Windows.Controls.Layout.Toolkit. and System.Windows.Controls.Toolkit

Wednesday, October 14, 2009

ErrorCode:4001 ErrorType:MediaError AG_E_NETWORK_ERROR

Hi all,

ErrorCode:4001 ErrorType:MediaError AG_E_NETWORK_ERROR

I get the above error when i play a media file. It ruins my whole day.
At last i found by adding the media file in the Bin Debug/Release folder and in the web i have added in the client bin folder. It solve my issue