<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Welcome to ShanthaKumar&#039;s Blog &#187; Silverlight</title>
	<atom:link href="http://ktskumar.com/blog/tag/silverlight/feed/" rel="self" type="application/rss+xml" />
	<link>http://ktskumar.com/blog</link>
	<description>SharePoint, Silverlight and more.........</description>
	<lastBuildDate>Thu, 10 Jun 2010 01:42:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Integrating Silverlight and HTML</title>
		<link>http://ktskumar.com/blog/2009/08/15/integrating-silverlight-and-html/</link>
		<comments>http://ktskumar.com/blog/2009/08/15/integrating-silverlight-and-html/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 17:02:33 +0000</pubDate>
		<dc:creator>Shantha Kumar</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Integration]]></category>

		<guid isPermaLink="false">http://ktskumar.com/blog/?p=207</guid>
		<description><![CDATA[
Today I have come up with simple post on Silverlight on integrating silverlight contents in html page and html contents in Silverlight.

The following image was the preview of our sample integration code.



Step 1:Create a Silverlight Application Project ,
Step 2:In the Xaml file, Add the following controls ,

&#60;TextBlock x:Name=&#8221;SL_txtBlock&#8221; TextWrapping=&#8221;Wrap&#8221; Margin=&#8221;167,133,62,0&#8243; Height=&#8221;45&#8243; VerticalAlignment=&#8221;Top&#8221; d:LayoutOverrides=&#8221;HorizontalAlignment&#8221; FontFamily=&#8221;Georgia&#8221; FontSize=&#8221;13.333&#8243; [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Today I have come up with simple post on Silverlight on integrating silverlight contents in html page and html contents in Silverlight.</p>
<p>
The following image was the preview of our sample integration code.<br />
<br />
<img src="http://www.ktskumar.com/images/HSLimg.JPG" alt="Html &#038; Silverlight integration preview" /></p>
<ul>
<li>Step 1:Create a Silverlight Application Project ,</li>
<li>Step 2:In the Xaml file, Add the following controls ,</li>
<p>
<div class="codecss">&lt;TextBlock x:Name=&#8221;SL_txtBlock&#8221; TextWrapping=&#8221;Wrap&#8221; Margin=&#8221;167,133,62,0&#8243; Height=&#8221;45&#8243; VerticalAlignment=&#8221;Top&#8221; d:LayoutOverrides=&#8221;HorizontalAlignment&#8221; FontFamily=&#8221;Georgia&#8221; FontSize=&#8221;13.333&#8243; Foreground=&#8221;White&#8221; /&gt;</p>
<p>&lt;Button x:Name=&#8221;SL_btn&#8221; Content=&#8221;Add Text to HTML&#8221; Margin=&#8221;129,81,0,85&#8243; Click=&#8221;SL_btn_Click&#8221; HorizontalAlignment=&#8221;Left&#8221; Width=&#8221;144&#8243; /&gt;</p>
<p>&lt;TextBox x:Name=&#8221;SL_txtbx&#8221; Height=&#8221;29&#8243; Margin=&#8221;167,37,62,0&#8243; VerticalAlignment=&#8221;Top&#8221; TextWrapping=&#8221;Wrap&#8221; d:LayoutOverrides=&#8221;HorizontalAlignment&#8221; FontFamily=&#8221;Georgia&#8221; FontSize=&#8221;13.333&#8243;/&gt;</p>
</div>
<p>The TextBlock control used to display the contents coming from the HTML,<br />
Button event will updates the contents in html page<br />
The TextBox text is sent to the html page using Button OnClick event.</p>
<li>Step 3: Find the html page will Silverlight by default and then add the following html lines below the &lt;div id=&#8221;silverlightControlHost&#8221;&gt; … &lt;/div&gt; tag</li>
<li>Step 4:
<p>
<div class="codecss">&lt;input type=&#8221;text&#8221; id=&#8221;htxtbx&#8221; /&gt;&lt;br /&gt;<br />
&lt;input id=&#8221;hbtn&#8221; type=&#8221;button&#8221; value=&#8221;Add text to Silverlight&#8221; onclick=&#8221;hbtn_click()&#8221; /&gt;&lt;br /&gt;<br />
&lt;div id=&#8221;slcontent&#8221;&gt;&lt;/div&gt;</div>
</p>
</li>
<li>Step 5: First of all, we can see how we send the values from Silverlight to Html page.<br />
Before going to coding, we have to add System.Windows.Browser namespace as reference to the project.</li>
<li>Step 6: And then add the following snippet within Button Click event in Silverlight code file,
<div class="codecss">
<p>
using System.Windows.Browser;</p>
<p>private void SL_btn_Click(object sender, System.Windows.RoutedEventArgs e)<br />
{<br />
//Represents the HTML document in the browser<br />
HtmlDocument doc = HtmlPage.Document;<br />
//Add the Silverlight textbox content to the HTML page.<br />
doc.GetElementById(&#8221;slcontent&#8221;).SetAttribute(&#8221;innerHTML&#8221;, SL_txtbx.Text);<br />
}</p>
</div>
<p>Adding the Silverlight textbox value to the html page within the div tag (which has the id as slcontent)…</li>
<li>Step 7: Now we will see how to send the data to silverlight from html,<br />
At First check whether the Silverlight Object tag has the id attribute, if not add the attribute as id=&#8221;silverlightControl&#8221;</li>
<li>Step 8: And the add the following javascript to the head section of the html page.
<p>
<div class="codecss">&lt;script&gt;<br />
function hbtn_click(sender,e)<br />
{<br />
var sl_control = document.getElementById(&#8221;SilverlightControl&#8221;);<br />
var text = sl_control.content.findName(&#8221;SL_txtBlock&#8221;);<br />
text["Text"] = document.getElementById(&#8221;htxtbx&#8221;).value;<br />
}<br />
&lt;/script&gt;</div>
</p>
<p> </li>
</ul>
<p>The hbtn_click function will be invoked when ever the button click occurs,</p>
<p>The first line within the function get the Silverlight control using id,_</p>
<p>control.content.findName(&#8221;SL_txtBlock&#8221;); used to the get the control with in the Silverlight by using controlname,</p>
<p>text["Text"] = document.getElementById(&#8221;htxtbx&#8221;).value, which assign the value of textbox in html page to Silverlight TextBox Control.</p></div>
<div>
<p><h2><a href="http://ktskumar.com/Silverlight/HSLIntegrate.html" target="_blank">Demo</a></h2>
<h3><a href="http://ktskumar.com/samples/HSLInteract.zip" target="_blank">Source Code</a></h3>
</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://ktskumar.com/blog/2009/08/15/integrating-silverlight-and-html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight webpart for SharePoint:</title>
		<link>http://ktskumar.com/blog/2008/03/01/silverlight-webpart-for-sharepoint/</link>
		<comments>http://ktskumar.com/blog/2008/03/01/silverlight-webpart-for-sharepoint/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 10:39:13 +0000</pubDate>
		<dc:creator>Shantha Kumar</dc:creator>
				<category><![CDATA[MOSS]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://ktskumar.wordpress.com/?p=12</guid>
		<description><![CDATA[In this post, we are going to see integrating the webpart with Silverlight contents on SharePoint Site.
 For that, we need to combine all required java script and Xaml files (used to display the Silverlight content) in to single assembly without any dependent files. It makes sense to embed the Xaml and java script file as [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin:0;" align="left"><span style="font-family:Times New Roman;">In this post, we are going to see integrating the webpart with Silverlight contents on SharePoint Site.</span></p>
<p class="MsoNormal" style="margin:0;" align="left"><span style="font-family:Times New Roman;"><span> </span>For that, we need to combine all required java script and Xaml files (used to display the Silverlight content) in to single assembly without any dependent files. It makes sense to embed the Xaml and java script file as a resource and reference it in programming usin<a title="im2.jpg" href="http://ktskumar.files.wordpress.com/2008/03/im2.jpg"></a>g the WebResource.axd handler mechanism for extracting embedded re<a title="im11.jpg" href="http://ktskumar.files.wordpress.com/2008/03/im11.jpg"></a>sources.</span></p>
<p align="left"> </p>
<p class="MsoNormal" style="margin:0;" align="left"><span style="font-family:Times New Roman;">I list out the following steps to add the Silverlight Content to SharePoint WebPart,</span></p>
<p class="ListParagraphCxSpFirst" style="text-indent:-.25in;margin:0 0 0 .5in;" align="left"><span style="font-family:Times New Roman;"><span>1.<span style="font:7pt 'Times New Roman';">      </span></span>Create a Webpart project and create or add the required java script and Xaml files to the project.</span></p>
<p class="ListParagraphCxSpMiddle" style="margin:0 0 0 .5in;" align="left"><span style="font-family:Times New Roman;">I used three files, are Silverlight.js, Scene.js and Scene.xaml</span></p>
<p class="ListParagraphCxSpMiddle" style="text-indent:-.25in;margin:0 0 0 .5in;" align="left"><span style="font-family:Times New Roman;"><span>2.<span style="font:7pt 'Times New Roman';">      </span></span>Set the BuildAction property to “Embedded Resource” in properties window for each java script and Xaml.</span></p>
<p class="ListParagraphCxSpMiddle" style="margin:0 0 0 .5in;" align="left"><span style="font-family:Times New Roman;">This will use to include the files as Resources in an assembly.</span></p>
<p align="left"> </p>
<p class="ListParagraphCxSpLast" style="margin:0 0 0 .5in;" align="left"><span><span><span style="font-family:Times New Roman;">                    <span style="font-size:12pt;font-family:'Times New Roman';"> <a title="im11.jpg" href="http://ktskumar.files.wordpress.com/2008/03/im11.jpg"><img src="http://ktskumar.files.wordpress.com/2008/03/im11.jpg" alt="im11.jpg" /></a>  <a title="im2.jpg" href="http://ktskumar.files.wordpress.com/2008/03/im2.jpg"><img src="http://ktskumar.files.wordpress.com/2008/03/im2.jpg" alt="im2.jpg" /></a></span></span></span></span></p>
<p align="left"> </p>
<p class="ListParagraphCxSpFirst" style="text-indent:-.25in;margin:0 0 0 .5in;" align="left"><span style="font-family:Times New Roman;"><span>3.<span style="font:7pt 'Times New Roman';">      </span></span>Add the assembly-level attribute System.Web.UI.WebResource to grant permission for these resources to be served by WebResource.axd and to associate MIME type for the response.</span></p>
<p align="left"><span style="font-family:Times New Roman;"> </span><span style="font-size:10pt;font-family:'Courier New';">[<span style="color:blue;">assembly</span>: <span style="color:#2b91af;">WebResource</span>(<span style="color:#a31515;">"Ktskumar.SLContent.Silverlight.js"</span>, <span style="color:#a31515;">"text/javascript" </span>)]</span></p>
<div>
<pre><span style="font-size:10pt;font-family:'Courier New';">[<span style="color:blue;">assembly</span>: <span style="color:#2b91af;">WebResource</span>(<span style="color:#a31515;">"Ktskumar.SLContent.Scene.js"</span>, <span style="color:#a31515;">"text/javascript"</span>)]</span></pre>
</div>
<p class="MsoNormal" style="margin:0;" align="left"><span style="font-size:10pt;font-family:'Courier New';">[<span style="color:blue;">assembly</span>: <span style="color:#2b91af;">WebResource</span>(<span style="color:#a31515;">"Ktskumar.SLContent.Scene.xaml"</span>, <span style="color:#a31515;">"text/xml"</span>)]</span></p>
<p class="ListParagraphCxSpFirst" style="margin:0 0 0 .5in;" align="left"><span style="font-family:Times New Roman;">Ktskumar.SLContent represents the namespace, Now JavaScript and Xaml files are compiled into my assembly as embedded resources.</span></p>
<p align="left"> </p>
<p class="ListParagraphCxSpMiddle" style="text-indent:-.25in;margin:0 0 0 .5in;" align="left"><span style="font-family:Times New Roman;"><span>4.<span style="font:7pt 'Times New Roman';">      </span></span>Now, we can use the RegisterClientScriptresource() method of the Page.ClientScriptManagerclass to rendered the page with the referenced files.</span></p>
<p align="left"><span style="font-family:Times New Roman;"> </span><span style="font-size:10pt;color:blue;font-family:'Courier New';">this</span><span style="font-size:10pt;font-family:'Courier New';">.Page.ClientScript.RegisterClientScriptResource(GetType(), <span style="color:#a31515;">&#8220;Ktskumar.SLContent.Silverlight.js&#8221;</span>);</span></p>
<p><span style="font-size:10pt;font-family:'Courier New';"><span style="color:blue;">this</span>.Page.ClientScript.RegisterClientScriptResource(GetType(), <span style="color:#a31515;">&#8220;Ktskumar.SLContent.Scene.js&#8221;</span>);&lt;/span</span><span style="font-size:10pt;font-family:'Courier New';"> </span></p>
<div></div>
<p><span style="font-size:10pt;font-family:'Courier New';"></p>
<p class="ListParagraphCxSpFirst" style="margin:0 0 0 .5in;" align="left"><span style="font-family:Times New Roman;">Include the above lines in the PreRender method to register the javascript files for the webpart.</span></p>
<p align="left"> </p>
<p class="ListParagraphCxSpLast" style="text-indent:-.25in;margin:0 0 0 .5in;" align="left"><span style="font-family:Times New Roman;"><span>5.<span style="font:7pt 'Times New Roman';">      </span></span>Add the following lines to the RenderWebPart method to host the &lt;div&gt; tag and call the Silverlight content to the webpart,</span></p>
<p align="left"><span style="font-family:Times New Roman;"> </span><span style="font-size:10pt;color:blue;font-family:'Courier New';">string</span><span style="font-size:10pt;font-family:'Courier New';"> strLoad = <span style="color:#a31515;">&#8220;Silverlight.createDelegate(scene, scene.handleLoad)&#8221;</span>;</span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;&lt;div id=&#8217;&#8221;</span> + <span style="color:blue;">this</span>.ClientID + <span style="color:#a31515;">&#8220;&#8216; Style=&#8221;Width:500px;Height:200px&#8221;&gt;&#8221;</span>);</span><span style="font-size:10pt;font-family:'Courier New';"> </span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;&lt;script type=&#8217;text/javascript&#8217;&gt;&#8221;</span>);</span><span style="font-size:10pt;font-family:'Courier New';"><span>           </span></span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';"></span><span style="font-size:10pt;font-family:'Courier New';"></span><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;if (!window.Silverlight)&#8221;</span>);</span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;window.Silverlight = {};&#8221;</span>);</span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;Silverlight.createDelegate = function(instance, method) {&#8221;</span>);</span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;return function() {&#8221;</span>);</span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;return method.apply(instance, arguments);&#8221;</span>);</span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;}}&#8221;</span>);</span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;var scene = new Scene();&#8221;</span>);</span><span style="font-size:10pt;font-family:'Courier New';"> </span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;Silverlight.createObjectEx({&#8221;</span>);</span><span style="font-size:10pt;font-family:'Courier New';"> </span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;source: &#8216;&#8221;</span> + <span style="color:blue;">this</span>.Page.ClientScript.GetWebResourceUrl(GetType(), <span style="color:#a31515;">&#8220;Ktskumar.SLContent.Scene.xaml&#8221;</span>) + <span style="color:#a31515;">&#8220;&#8216;,&#8221;</span>);</span><span style="font-size:10pt;font-family:'Courier New';"> </span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;parentElement: document.getElementById(&#8217;&#8221;</span> + <span style="color:blue;">this</span>.ClientID+<span style="color:#a31515;">&#8220;&#8216;),&#8221;</span>);</span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;id: &#8216;&#8221;</span> + <span style="color:blue;">this</span>.ClientID + <span style="color:#a31515;">&#8220;_ctrl&#8217;&#8221;</span> + <span style="color:#a31515;">&#8220;,&#8221;</span>);</span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;properties: {width:&#8217;100%&#8217;, height:&#8217;100%&#8217;, version:&#8217;1.0&#8242; },&#8221;</span>);</span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;events:{ onLoad: &#8220;</span>+strLoad+<span style="color:#a31515;">&#8220;, onError: null<span>  </span>},&#8221;</span>);</span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;context: null&#8221;</span>);</span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;});&#8221;</span>);</span><span style="font-size:10pt;font-family:'Courier New';"> </span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">output.WriteLine(<span style="color:#a31515;">&#8220;&lt;/script&gt;&lt;/div&gt;&#8221;</span>);</span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';"> </span><span style="font-size:10pt;font-family:'Courier New';">Now you can install webpart to the SharePoint and see the Silverlight contents present in the SharePoint WebPart.</span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';">Coming soon, I will upload the source code for this webpart and more activities to come on Integrating the Silverlight with SharePoint. So always tuneup this blog.</span></p>
<p align="left"><span style="font-size:10pt;font-family:'Courier New';"><a title="Click Here" href="http://cid-c6404b89971e6efa.skydrive.live.com/self.aspx/Source%20Codes/Ktskumar.SLContent.zip">Click here</a> to download the source code for the above example.</span></p>
<p> </p>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://ktskumar.com/blog/2008/03/01/silverlight-webpart-for-sharepoint/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
