Click here to Skip to main content
15,887,135 members
Articles / Desktop Programming / XAML

Silverlight 1.0 Full JavaScript Intellisense

Rate me:
Please Sign up or sign in to vote.
3.81/5 (16 votes)
21 Dec 2007Ms-PL11 min read 31.9K   141   17  
An article about Silverlight 1.0 full JavaScript Intellisense
<html dir="ltr" xmlns:mshelp="http://msdn.microsoft.com/mshelp"
xmlns:silverlightsdk="http://msdn.microsoft.com/silverlight" xmlns=
"http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="online documentation, web online help, web help, chm2web" />
<meta http-equiv="Content-Style-Type" content="text/css" />

<meta name="generator" content="chm2web Standard 2.7 (unicode)" />
<meta http-equiv="Content-Type" content=
"text/html; charset=utf-8" />
<title>Text Property (TextElement)</title>
<link rel="stylesheet" href="../../default.css" type="text/css" />

<script type="text/JavaScript" src="../../files/supply.js"></script>
<script type="text/JavaScript">
chmtop.c2wtopf.pageid = "reference/p_textelement_text.htm";
</script>

</head>
<body topmargin="0"><script type="text/JavaScript"> 
if (window.name != "content") 
  document.write(" <table width=\"100%\" bgcolor=\"#e1e1e1\"cellspacing=\"2\" cellpadding=\"0\" style=\"border-collapse: collapse; font-family: sans-serif; font-size: 14px; color: #000000; text-decoration: none;  \"> <tr> <td align=\"center\" style=\"border-bottom: 2px solid gray\" > <br>&nbsp;Click <a href=\"../../index.html?page=source%2freference%2fp_textelement_text.htm\">here</a> to show toolbars of the Web Online Help System: <a href=\"../../index.html?page=source%2freference%2fp_textelement_text.htm\">show toolbars</a><br>&nbsp;</td></tr></table><br> "); 
</script>
<!-- !chm2web! -->

<span id="sdkbannersection"></span>
<div class="tableSection"><span id="sdkbannersection"></span>
<table class="buttonbarshade" cellspacing="0">
<tr>
<td>&nbsp;</td>
</tr>
</table>
</div>

<div class="tableSection"><span id="sdkbannersection"></span>
<table class="buttonbartable" cellspacing="0">
<tr id="hdr">
<td class="runninghead" nowrap="nowrap"><img src=
"../common/logo.png" height="21" alt="Silverlight SDK" />
</td>
</tr>
</table>
</div>

<p><span class="betaboilerplate"><font color="gray" pointsize="8.5"
face="Verdana">[This topic is pre-release documentation and is
subject to change in future releases. Blank topics are included as
placeholders.]</font></span>
</p>

<h1><a name="silverlight_textelement_text_property"></a>Text
Property (TextElement)</h1>

<div id="mainSection">
<div id="mainBody">
<p>Gets or sets the text contents of the text element.</p>

<div id="syntaxblock">
<table class="auto_syntaxtable" id="syntaxtable" style=
"width: 90%; background: #CCCCCC; border: none;">
<tr id="xamlSyntaxBlock">
<th class="syntaxblocklanguage" nowrap="nowrap" style=
"width: 150px; background: #EEEEEE; vertical-align: top;">XAML</th>
<td class="syntaxblockcode" style="background:white;">
<div class="codesyntax" style=
"font-family: 'Courier New', Courier, monospace;">
&lt;<i>object</i>&nbsp;<b>Text</b>="<b>String</b>" .../&gt;</div>
</td>
</tr>

<tr id="scriptingSyntaxBlock">
<th class="syntaxblocklanguage" nowrap="nowrap" style=
"width: 150px; background: #EEEEEE; vertical-align: top;">
Scripting</th>
<td class="syntaxblockcode" style="background:white;">
<div class="codesyntax" style=
"font-family: 'Courier New', Courier, monospace;"><i>value</i> =
<i>object</i>.<b>text</b><br />
<i>object</i>.<b>text</b> = <i>value</i></div>
</td>
</tr>
</table>
</div>
<span id="propertyvalue"></span>
<h4><span id="propertyvalue">Property Value</span>
</h4>

<p><b>String</b>
</p>

<p>A string specifying the text contents of this text element.</p>

<p>This property is read/write. The default value is an empty
string.</p>

<h4>Remarks</h4>

<p>The <a href="o_textblock.htm">TextBlock</a> object is the
primary text element for displaying text in Silverlight
applications. A <a href="o_textblock.htm">TextBlock</a> can be
thought of as having two simultaneous object models within
it:&lt;/&gt;</p>

<ul>
<li>A representation as a <b>Text</b> property, which represents
only string content (no formatting other than the formatting
declared at the <a href="o_textblock.htm">TextBlock</a>
level).</li>

<li>A representation as an <a href=
"p_textblock_inlines.htm">Inlines</a> collection. The collection
contains primarily <a href="o_run.htm">Run</a> objects, each of
which can declare its own formatting properties such as <a href=
"p_textelement_fontsize.htm">FontSize</a>. The <b>Text</b> property
still returns a value (the appended text of all <a href=
"o_run.htm">Run</a> elements in the <a href=
"p_textblock_inlines.htm">Inlines</a>) but does not capture any
formatting applied to the <a href="o_run.htm">Run</a> elements. If
created from XAML as inner text of a &lt;TextBlock&gt; tag, or by
setting to <b>Text</b> property, the <a href=
"p_textblock_inlines.htm">Inlines</a> collection contains a single
<a href="o_run.htm">Run</a> that contains that text.</li>
</ul>

<p>You can choose to work with either object model. However, you
should be aware that if you adjust the text by appending to the
<b>Text</b> value, when the text is actually a series of text
elements with individual formatting in an <a href=
"p_textblock_inlines.htm">Inlines</a> collection, you will flatten
the previous <a href="p_textblock_inlines.htm">Inlines</a>
collection content and replace it with a single new unformatted
<a href="o_run.htm">Run</a> with your new text. This generally is
not a desired behavior.</p>

<p>The following XAML example shows how to define a
<b>TextBlock</b> element and set its <b>Text</b> property to a
character string:</p>

<div class="snippetdistributor_codesnippet" id=
"text_snip#TextBlockSimple" language_override="XAML">
<div style="width: 99%;">
<table class="codeexampletable" style=
"border: 1px solid #999999; background: #CCCCCC; width: 99%;">
<tr>
<th class="codelanguagecell" style=
"background: #CCCCCC; text-align: left;">XAML</th>
</tr>

<tr>
<td class="codeblockcell" style=
"background: #e6e6e6; border: none;">
<pre class="codeblock" style=
"background: transparent; border: none; margin: 0px; padding: 0px; font-family:'Courier New', Courier, monospace;">

&lt;Canvas
  xmlns="http://schemas.microsoft.com/client/2007"&gt;
  &lt;TextBlock Text="Hello, world!" /&gt;
&lt;/Canvas&gt;
</pre>
</td>
</tr>
</table>
</div>
</div>
<br />

<p>The following image displays the result of the previous XAML
content example:</p>
<img border="0" src="../conceptual/images/textblock_01.png" width=
"321" height="61" /><br />
<b>TextBlock rendering with default font properties</b><br />

<p>There are several interesting items to note about the display of
the rendered text:</p>

<ul>
<li>The default value of the <a href=
"p_textelement_fontsize.htm">FontSize</a> property of the rendered
<b>TextBlock</b> is 14.666 pixels, which is exactly 11 points.</li>

<li>The default value of the <a href=
"p_textelement_fontfamily.htm">FontFamily</a> property of the
rendered <b>TextBlock</b> is "Lucida Sans Unicode, Lucida
Grande".</li>

<li>No font files on the hosting Web server, or residing in the
same directory location as the XAML content, are required to enable
the default font.</li>
</ul>

<p>When setting text in a <b>TextBlock</b>, it is not necessary in
XAML to explicitly specify the <b>Text</b> property:</p>

<div class="snippetdistributor_codesnippet" id=
"text_snip#TextBlockSimple2" language_override="XAML">
<div style="width: 99%;">
<table class="codeexampletable" style=
"border: 1px solid #999999; background: #CCCCCC; width: 99%;">
<tr>
<th class="codelanguagecell" style=
"background: #CCCCCC; text-align: left;">XAML</th>
</tr>

<tr>
<td class="codeblockcell" style=
"background: #e6e6e6; border: none;">
<pre class="codeblock" style=
"background: transparent; border: none; margin: 0px; padding: 0px; font-family:'Courier New', Courier, monospace;">

&lt;Canvas
  xmlns="http://schemas.microsoft.com/client/2007"&gt;
  &lt;TextBlock&gt;Hello, world!&lt;/TextBlock&gt;
&lt;/Canvas&gt;
</pre>
</td>
</tr>
</table>
</div>
</div>
<br />

<p><b>Note:</b> Any leading or trailing whitespace is not preserved
when setting the <b>Text</b> property.</p>

<p>For more information on text and fonts, see <a href=
"../conceptual/text_and_fonts_overview.htm">Text and Fonts
Overview</a>.</p>
<span id="appliestosection"></span>
<h4><span id="appliestosection">Applies To</span>
</h4>

<p><a href="o_run.htm">Run</a>, <a href=
"o_textblock.htm">TextBlock</a></p>
<span id="seealsosection"></span>
<h4><span id="seealsosection">See Also</span>
</h4>

<p><a href="../conceptual/text_and_fonts_overview.htm">Text and
Fonts Overview</a>, <a href=
"p_textelement_fontfamily.htm">FontFamily</a>, <a href=
"p_textelement_fontsize.htm">FontSize</a>, <a href=
"p_textelement_fontstretch.htm">FontStretch</a>, <a href=
"p_textelement_fontstyle.htm">FontStyle</a>, <a href=
"p_textelement_fontweight.htm">FontWeight</a></p>
</div>
</div>

<script type="text/JavaScript">
var fe = FindFrame("toc", top);
if ((fe != null) && (chmtop.c2wtopf.jstree != null)) {
  if (chmtop.c2wtopf.FITEMS[chmtop.c2wtopf.pagenum] != chmtop.c2wtopf.pageid)
    chmtop.c2wtopf.jstree.OpenTreeNode("source/" + chmtop.c2wtopf.pageid);
}
</script>

<!-- CHM2WEB -->
<!-- DO NOT DELETE OR MODIFY THIS CODE WITHOUT 
     WRITTEN PERMISSION OF A!K RESEARCH LABS -->
<table width="100%" cellspacing="0" cellpadding="0" 
style="margin-top: 0pt; border-collapse: collapse;"> 
<tr> <td align="right" style="background-color:white; border-top: 1px solid gray;"> 
<a href="http://chm2web.aklabs.com" target="_blank" style="font-family: sans-serif;  font-size: 11px; text-decoration: none;"><font color="gray">Converted from CHM to HTML with <b>chm2web Standard 2.7 (unicode)</b></font></a>
</td></tr></table> 
<!-- /CHM2WEB -->

</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
JustinAngel.Net, Senior .Net consultant
Israel Israel
Justin-Josef Angel is a C# Microsoft Most Valuable professional, a Senior .Net consultant in Israel with 4 years of .Net experience and has 8 years of Web experience.

Justin's been working this past year on two Enterprise sized Silverlight projects with his customers. During that time he's gained a real-insight into Silverlight's inner workings and how to integrate Silverlight into the real world of software development. Additionally, During that time he's developed a few well-known projects like the "Silverlight 1.0 Javascript Intellisense", "Silverlight 1.1 Hebrew & Arabic Languages support" and a few others you might know.

Justin is also a seasoned presenter with an impressive track-record of talking in front of thousands of people in Israel.

Justin owns the first .Net blog written in Hebrew - http://www.JustinAngel.Net .
And he also owns an additional blog with mixed Hebrew & English content - http://blogs.Microsoft.co.il/blogs/JustinAngel.

A full list of his articles (all 100+ of them) can be found at: http://www.JustinAngel.Net/#index




Comments and Discussions