No path is too difficult. No destination is too far !
Posts tagged SilverLight
How to pass InitParameters to Silverlight in HTML object control
Mar 3rd
There are three different ways in which we can pass parameters to Silverlight from the HTML side:
1. Pass parameters using the HTML object control.
This may be the case using pure HTML page to call silverlight control in it or may be the simple ASp.Net page as usual.
<object width=”100%” height=”100%”>
<param name=”source” value=”ClientBin/SomethingFunny.xap” />
<!– you can pass InitParameters to it. Pass anything like EndPointURI, EndPointName or Even StartPage –>
<param name=”InitParameters” value=”startPage=UnRegisteredLandingPage, EndPointURI=http://www.sehajpal.com/testservice.svc” />
</object>
2. Using ASP.Net page to call silverlight control in it, we can easily pass parameters to it in anyway. One of the old tricks is to have an asp-literal control on the HTML side i.e. MarkUp side, and set its text to the desired HTML output fom code behind.
In the markup:
<asp:Literal ID=”litParam” runat=”server” />In the code behind:
this.litParam.Text = String.Format(“<param name=\”ParamInitParameters\” value=\”{0}\” />”, sInitParms);
3. Using asp-silverlight control to host Silverlight application in an ASP.net website as usual. This is pretty neat approach in terms of playing around with parameters and properties of control hosting the Silverlight app.
In the markup:
<asp:Silverlight ID=”SLControl” runat=”server” Width=”100%” Height=”100%” />
In the code behind:
SLControl.InitParameters = “EndPointURI=” + endPointURI + “,EndPointName=commonservice, UserCredentials=” + CredentialString;
Hope it works for you in different scenarios.
Bind with Enum in Silverlight
Feb 23rd
Silverlight doesn’t have any kind of ObjEctDataProvider with it. So the famous example of binding the controls with an ObjectDataProvider doesn’t work with silverlight as it works with WPF
<UserControl.Resources>
<ObjectDataProvider MethodName=“GetValues” ObjectType=”{x:Type sys:Enum}“ x:Key=“AlignmentValues”> <ObjectDataProvider.MethodParameters>
<x:Type TypeName=“HorizontalAlignment” />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
This can be done via code behind in the Silverlight. Just add a reference to the Reflection assembly.
using System.Reflection;
Use this simple function to get IEnumerable collection out of Enum type.
public IEnumerable<Enum> GetEnumValues(Enum enumeration)
{
return from gField in enumeration.GetType().GetFields(BindingFlags.Static | BindingFlags.Public)
select (Enum)gField.GetValue(enumeration);
}
Just bind the results of this function with your control and its done !
ComboFrom.ItemsSource = GetEnumValues(new SehajService.Currency());
Unable to debug the silverlight project
Feb 18th
I have some strange thing happening in my application. I was able to debug anything but silverlight code !!
I did so much of RnD on net and tried various tricks, but only this thing worked : -
When you add a Silverlight project to a asp.net solution, you create 2 projects…
A. the startup project (interface starter)
B. the interface itself
1. right click on the startup project (SilverlightWeb — the one with default.aspx in it )…
2. click on ‘Property Pages’
3. open ‘Start Options’ Tab
4. enable Silverlight Debugger
5. OK
This was the solution for me
Versioning problem in reference.cs in WCF service consumption in Silverlight 2
Feb 18th
A starnge problem occured when I was trying to add reference to one of my WCF service in my silverlight project. When deeply researched I found that some of the data contracts have been references twice in the reference.cs i.e. some classes with version 3.0.0.0 and some with 2.0.0.0 version. Strange!!
A quick work around was to generate the reference via svcutil.exe and it worked well in case where the project was justa relay service and not the silverlight application. In silverlght app, it throws the error for async and completed methods. Then I used SLSvcutil.exe i.e. svcutil for silverlight which is bundled with silverlight 3 only. I used this and generated the refences.cs for me. One problem left is FAULTCONTRACTS in the code. That i removed manually and it is working now.