Sunday, September 12, 2010

Charts in Silverlight

hi,
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.

http://visifire.codeplex.com/

Wcf Data Service

Hi
I have created a basic WCF Dataservices using ADO.net 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;
}

[WebGet]
public string GetUsers(string userId)
{
return "my data";
}

my browser uri is
http://localhost:50449/DataService.svc/GetUsers?userId='1'


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
http://localhost:50449/DataService.svc/GetUsers()?userId='1'

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)
{

try
{
// 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

Hi,
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.
Example:
Image img = new Image();

Uri uri = new Uri("http://YourServer.com/MyImage.png", UriKind.Absolute);
BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage(uri);
bi.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
img.Source = bi;
LayoutRoot.Children.Add(img);

Monday, November 30, 2009

Paging in wrapPanel

Here is the paging Functionality in Wrap Panel
I have added Wrap panel using the namespace system.windows.Controls.toolkit 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()
{
InitializeComponent();
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)
{
Paging();
}
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));
PageStackPanel.Children.Clear();
myWrapPanel.Children.Clear();
if (pagecount != 1)
{
for (int i = 0; i <= pagecount; i++) {
HyperlinkButton href = new HyperlinkButton();
href.Content = i + 1;
href.Click += new RoutedEventHandler(href_Click);
PageStackPanel.Children.Add(href);
}
}
}
GetInteractivity(1);
}

void href_Click(object sender, RoutedEventArgs e)
{
HyperlinkButton hf = sender as HyperlinkButton; GetInteractivity(Convert.ToInt32(hf.Content));
}
void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
try
{
xmlParser = new XMLParser(e.Result);
BindXML(); webClient.OpenReadCompleted -= new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
totalSize = interactivityList.Count; Paging();
GetInteractivity(1);
}
catch (Exception ex) { }
}
private void GetInteractivity(double pgSize)
{
myWrapPanel.Children.Clear();
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;
myWrapPanel.Children.Add(img);
myWrapPanel.Children.Add(rect);
}
}
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();
interactivityList.Add(interactivity);
}
}
} public class Interactivity
{
public string imagePath { get; set; }
public string xapfilePath { get; set; }
}


NOTE:

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