<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Mallesh</title>
	<atom:link href="http://malleshv.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://malleshv.wordpress.com</link>
	<description></description>
	<lastBuildDate>Sun, 20 Dec 2009 08:23:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='malleshv.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/2a33e2b4e81289e3c5b4fbe7205d2103?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Mallesh</title>
		<link>http://malleshv.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://malleshv.wordpress.com/osd.xml" title="Mallesh" />
	<atom:link rel='hub' href='http://malleshv.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Asp.net MVC the new Microsoft web development</title>
		<link>http://malleshv.wordpress.com/2009/12/20/asp-net-mvc-the-new-microsoft-web-development/</link>
		<comments>http://malleshv.wordpress.com/2009/12/20/asp-net-mvc-the-new-microsoft-web-development/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 08:23:23 +0000</pubDate>
		<dc:creator>malleshv</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://malleshv.wordpress.com/?p=52</guid>
		<description><![CDATA[test<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=malleshv.wordpress.com&amp;blog=7188786&amp;post=52&amp;subd=malleshv&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><b>test</b></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/malleshv.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/malleshv.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/malleshv.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/malleshv.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/malleshv.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/malleshv.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/malleshv.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/malleshv.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/malleshv.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/malleshv.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/malleshv.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/malleshv.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/malleshv.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/malleshv.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=malleshv.wordpress.com&amp;blog=7188786&amp;post=52&amp;subd=malleshv&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://malleshv.wordpress.com/2009/12/20/asp-net-mvc-the-new-microsoft-web-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e7643e7e288f6580f0387f37fe6598a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">malleshv</media:title>
		</media:content>
	</item>
		<item>
		<title>Sql server coding best practices part2</title>
		<link>http://malleshv.wordpress.com/2009/08/18/sql-server-coding-best-practices-part2/</link>
		<comments>http://malleshv.wordpress.com/2009/08/18/sql-server-coding-best-practices-part2/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 07:36:03 +0000</pubDate>
		<dc:creator>malleshv</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://malleshv.wordpress.com/?p=49</guid>
		<description><![CDATA[•Always use a column list in your INSERT statements. This helps in avoiding problems when the table structure changes (like adding or dropping a column). Here&#8217;s an example which shows the problem. Consider the following table: CREATE TABLE EuropeanCountries ( CountryID int PRIMARY KEY, CountryName varchar(25) ) Here&#8217;s an INSERT statement without a column list [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=malleshv.wordpress.com&amp;blog=7188786&amp;post=49&amp;subd=malleshv&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>•Always use a column list in your INSERT statements. This helps in avoiding problems when the table structure changes (like adding or dropping a column). Here&#8217;s an example which shows the problem.</p>
<p>Consider the following table:</p>
<p>CREATE TABLE EuropeanCountries<br />
(<br />
CountryID int PRIMARY KEY,<br />
CountryName varchar(25)<br />
) </p>
<p>Here&#8217;s an INSERT statement without a column list , that works perfectly:</p>
<p>INSERT INTO EuropeanCountries<br />
VALUES (1, &#8216;Ireland&#8217;) </p>
<p>Now, let&#8217;s add a new column to this table:</p>
<p>ALTER TABLE EuropeanCountries<br />
ADD EuroSupport bit </p>
<p>Now run the above INSERT statement. You get the following error from SQL Server:</p>
<p>Server: Msg 213, Level 16, State 4, Line 1<br />
Insert Error: Column name or number of supplied values does not match table definition. </p>
<p>This problem can be avoided by writing an INSERT statement with a column list as shown below:</p>
<p>INSERT INTO EuropeanCountries<br />
(CountryID, CountryName)<br />
VALUES (1, &#8216;England&#8217;)</p>
<p>•Perform all your referential integrity checks and data validations using constraints (foreign key and check constraints) instead of triggers, as they are faster. Limit the use triggers only for auditing, custom tasks and validations that can not be performed using constraints. Constraints save you time as well, as you don&#8217;t have to write code for these validations, allowing the RDBMS to do all the work for you.</p>
<p>•Always access tables in the same order in all your stored procedures and triggers consistently. This helps in avoiding deadlocks. Other things to keep in mind to avoid deadlocks are: Keep your transactions as short as possible. Touch as few data as possible during a transaction. Never, ever wait for user input in the middle of a transaction. Do not use higher level locking hints or restrictive isolation levels unless they are absolutely needed. Make your front-end applications deadlock-intelligent, that is, these applications should be able to resubmit the transaction incase the previous transaction fails with error 1205. In your applications, process all the results returned by SQL Server immediately so that the locks on the processed rows are released, hence no blocking.</p>
<p>•Offload tasks, like string manipulations, concatenations, row numbering, case conversions, type conversions etc., to the front-end applications if these operations are going to consume more CPU cycles on the database server. Also try to do basic validations in the front-end itself during data entry. This saves unnecessary network roundtrips.</p>
<p>•If back-end portability is your concern, stay away from bit manipulations with T-SQL, as this is very much RDBMS specific. Further, using bitmaps to represent different states of a particular entity conflicts with normalization rules.</p>
<p>•Always add a @Debug parameter to your stored procedures. This can be of BIT data type. When a 1 is passed for this parameter, print all the intermediate results, variable contents using SELECT or PRINT statements and when 0 is passed do not print anything. This helps in quick debugging stored procedures, as you don&#8217;t have to add and remove these PRINT/SELECT statements before and after troubleshooting problems.</p>
<p>•Do not call functions repeatedly within your stored procedures, triggers, functions and batches. For example, you might need the length of a string variable in many places of your procedure, but don&#8217;t call the LEN function whenever it&#8217;s needed, instead, call the LEN function once, and store the result in a variable, for later use.</p>
<p>•Make sure your stored procedures always return a value indicating their status. Standardize on the return values of stored procedures for success and failures. The RETURN statement is meant for returning the execution status only, but not data. If you need to return data, use OUTPUT parameters.</p>
<p>•If your stored procedure always returns a single row resultset, consider returning the resultset using OUTPUT parameters instead of a SELECT statement, as ADO handles output parameters faster than resultsets returned by SELECT statements.</p>
<p>•Always check the global variable @@ERROR immediately after executing a data manipulation statement (like INSERT/UPDATE/DELETE), so that you can rollback the transaction in case of an error (@@ERROR will be greater than 0 in case of an error). This is important, because, by default, SQL Server will not rollback all the previous changes within a transaction if a particular statement fails. This behavior can be changed by executing SET XACT_ABORT ON. The @@ROWCOUNT variable also plays an important role in determining how many rows were affected by a previous data manipulation (also, retrieval) statement, and based on that you could choose to commit or rollback a particular transaction.</p>
<p>•To make SQL Statements more readable, start each clause on a new line and indent when needed. Following is an example:</p>
<p>SELECT title_id, title<br />
FROM titles<br />
WHERE title LIKE &#8216;%Computer%&#8217; AND<br />
      title LIKE &#8216;%cook%&#8217;</p>
<p>•Though we survived the Y2K, always store 4 digit years in dates (especially, when using cCHAR or INT datatype columns), instead of 2 digit years to avoid any confusion and problems. This is not a problem with DATETIME columns, as the century is stored even if you specify a 2 digit year. But it&#8217;s always a good practice to specify 4 digit years even with DATETIME datatype columns. </p>
<p>•As is true with any other programming language, do not use GOTO, or use it sparingly. Excessive usage of GOTO can lead to hard-to-read-and-understand code.</p>
<p>•Do not forget to enforce unique constraints on your alternate keys.</p>
<p>•Always be consistent with the usage of case in your code. On a case insensitive server, your code might work fine, but it will fail on a case sensitive SQL Server if your code is not consistent in case. For example, if you create a table in SQL Server or a database that has a case-sensitive or binary sort order, all references to the table must use the same case that was specified in the CREATE TABLE statement. If you name the table as &#8216;MyTable&#8217; in the CREATE TABLE statement and use &#8216;mytable&#8217; in the SELECT statement, you get an &#8216;object not found&#8217; error.</p>
<p>•Though T-SQL has no concept of constants (like the ones in the C language), variables can serve the same purpose. Using variables instead of constant values within your queries improves readability and maintainability of your code. Consider the following example: </p>
<p>SELECT OrderID, OrderDate<br />
FROM Orders<br />
WHERE OrderStatus IN (5,6) </p>
<p>The same query can be re-written in a mode readable form as shown below:</p>
<p>DECLARE @ORDER_DELIVERED, @ORDER_PENDING<br />
SELECT @ORDER_DELIVERED = 5, @ORDER_PENDING = 6</p>
<p>SELECT OrderID, OrderDate<br />
FROM Orders<br />
WHERE OrderStatus IN (@ORDER_DELIVERED, @ORDER_PENDING)</p>
<p>•Do not use column numbers in the ORDER BY clause. Consider the following example in which the second query is more readable than the first one:</p>
<p>SELECT OrderID, OrderDate<br />
FROM Orders<br />
ORDER BY 2</p>
<p>SELECT OrderID, OrderDate<br />
FROM Orders<br />
ORDER BY OrderDate </p>
<p>Well, this is all for now folks. I&#8217;ll keep updating this page as and when I have something new to add. I welcome your feedback on this, so feel free to email me. Happy database programming!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/malleshv.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/malleshv.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/malleshv.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/malleshv.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/malleshv.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/malleshv.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/malleshv.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/malleshv.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/malleshv.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/malleshv.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/malleshv.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/malleshv.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/malleshv.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/malleshv.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=malleshv.wordpress.com&amp;blog=7188786&amp;post=49&amp;subd=malleshv&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://malleshv.wordpress.com/2009/08/18/sql-server-coding-best-practices-part2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e7643e7e288f6580f0387f37fe6598a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">malleshv</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL Server Coding Conventions, Best Practices.</title>
		<link>http://malleshv.wordpress.com/2009/08/18/sql-server-coding-conventions-best-practices/</link>
		<comments>http://malleshv.wordpress.com/2009/08/18/sql-server-coding-conventions-best-practices/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 07:31:24 +0000</pubDate>
		<dc:creator>malleshv</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://malleshv.wordpress.com/?p=45</guid>
		<description><![CDATA[Here are some programming guidelines and best practices, keeping quality, performance and maintainability in mind. This list many not be complete at this moment, and will be constantly updated. BTW, special thanks to Tibor Karaszi (SQL Server MVP) and Linda (lindawie) for taking time to read this article and providing suggestions. •Decide upon a database [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=malleshv.wordpress.com&amp;blog=7188786&amp;post=45&amp;subd=malleshv&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here are some programming guidelines and best practices, keeping quality, performance and maintainability in mind. This list many not be complete at this moment, and will be constantly updated. BTW, special thanks to Tibor Karaszi (SQL Server MVP) and Linda (lindawie) for taking time to read this article and providing suggestions.</p>
<p>•Decide upon a database naming convention, standardize it across your organization, and be consistent in following it. It helps make your code more readable and understandable. Click here to see the database object naming convention that I follow.</p>
<p>•Make sure you normalize your data at least to the 3rd normal form. At the same time, do not compromise on query performance. A little bit of denormalization helps queries perform faster.</p>
<p>•Write comments in your stored procedures, triggers and SQL batches generously, whenever something is not very obvious. This helps other programmers understand your code clearly. Don&#8217;t worry about the length of the comments, as it won&#8217;t impact the performance, unlike interpreted languages like ASP 2.0.</p>
<p>•Do not use SELECT * in your queries. Always write the required column names after the SELECT statement, like:<br />
SELECT CustomerID, CustomerFirstName, City</p>
<p>This technique results in reduced disk I/O and better performance.</p>
<p>•Try to avoid server side cursors as much as possible. Always stick to a &#8216;set-based approach&#8217; instead of a &#8216;procedural approach&#8217; for accessing and manipulating data. Cursors can often be avoided by using SELECT statements instead.<br />
If a cursor is unavoidable, use a WHILE loop instead. I have personally tested and concluded that a WHILE loop is always faster than a cursor. But for a WHILE loop to replace a cursor you need a column (primary key or unique key) to identify each row uniquely. I personally believe every table must have a primary or unique key. Click here to see some examples of using a WHILE loop.</p>
<p>•Avoid the creation of temporary tables while processing data as much as possible, as creating a temporary table means more disk I/O. Consider using advanced SQL, views, SQL Server 2000 table variable, or derived tables, instead of temporary tables.</p>
<p>•Try to avoid wildcard characters at the beginning of a word while searching using the LIKE keyword, as that results in an index scan, which defeats the purpose of an index. The following statement results in an index scan, while the second statement results in an index seek:</p>
<p>SELECT LocationID FROM Locations WHERE Specialities LIKE &#8216;%pples&#8217;<br />
SELECT LocationID FROM Locations WHERE Specialities LIKE &#8216;A%s&#8217; </p>
<p>Also avoid searching using not equals operators ( and NOT) as they result in table and index scans.</p>
<p>•Use &#8216;Derived tables&#8217; wherever possible, as they perform better. Consider the following query to find the second highest salary from the Employees table:</p>
<p>SELECT MIN(Salary)<br />
FROM Employees<br />
WHERE EmpID IN<br />
(<br />
SELECT TOP 2 EmpID<br />
FROM Employees<br />
ORDER BY Salary Desc<br />
) </p>
<p>The same query can be re-written using a derived table, as shown below, and it performs twice as fast as the above query:</p>
<p>SELECT MIN(Salary)<br />
FROM<br />
(<br />
SELECT TOP 2 Salary<br />
FROM Employees<br />
ORDER BY Salary DESC<br />
) AS A </p>
<p>This is just an example, and your results might differ in different scenarios depending on the database design, indexes, volume of data, etc. So, test all the possible ways a query could be written and go with the most efficient one.</p>
<p>•While designing your database, design it keeping &#8220;performance&#8221; in mind. You can&#8217;t really tune performance later, when your database is in production, as it involves rebuilding tables andindexes, re-writing queries, etc. Use the graphical execution plan in Query Analyzer or SHOWPLAN_TEXT or SHOWPLAN_ALL commands to analyze your queries. Make sure your queries do an &#8220;Index seek&#8221; instead of an &#8220;Index scan&#8221; or a &#8220;Table scan.&#8221; A table scan or an index scan is a very bad thing and should be avoided where possible. Choose the right indexes on the right columns.</p>
<p>•Prefix the table names with the owner&#8217;s name, as this improves readability and avoids any unnecessary confusion. Microsoft SQL Server Books Online even states that qualifying table names with owner names helps in execution plan reuse, further boosting performance.</p>
<p>•Use SET NOCOUNT ON at the beginning of your SQL batches, stored procedures and triggers in production environments, as this suppresses messages like &#8216;(1 row(s) affected)&#8217; after executing INSERT, UPDATE, DELETE and SELECT statements. This improves the performance of stored procedures by reducing network traffic.</p>
<p>•Use the more readable ANSI-Standard Join clauses instead of the old style joins. With ANSI joins, the WHERE clause is used only for filtering data. Where as with older style joins, the WHERE clause handles both the join condition and filtering data. The first of the following two queries shows the old style join, while the second one shows the new ANSI join syntax:</p>
<p>SELECT a.au_id, t.title<br />
FROM titles t, authors a, titleauthor ta<br />
WHERE<br />
a.au_id = ta.au_id AND<br />
ta.title_id = t.title_id AND<br />
t.title LIKE &#8216;%Computer%&#8217;</p>
<p>SELECT a.au_id, t.title<br />
FROM authors a<br />
INNER JOIN<br />
titleauthor ta<br />
ON<br />
a.au_id = ta.au_id<br />
INNER JOIN<br />
titles t<br />
ON<br />
ta.title_id = t.title_id<br />
WHERE t.title LIKE &#8216;%Computer%&#8217;</p>
<p>•Do not prefix your stored procedure names with &#8220;sp_&#8221;. The prefix sp_ is reserved for system stored procedure that ship with SQL Server. Whenever SQL Server encounters a procedure name starting with sp_, it first tries to locate the procedure in the master database, then it looks for any qualifiers (database, owner) provided, then it tries dbo as the owner. So you can really save time in locating the stored procedure by avoiding the &#8220;sp_&#8221; prefix.</p>
<p>•Views are generally used to show specific data to specific users based on their interest. Views are also used to restrict access to the base tables by granting permission only on views. Yet another significant use of views is that they simplify your queries. Incorporate your frequently required, complicated joins and calculations into a view so that you don&#8217;t have to repeat those joins/calculations in all your queries. Instead, just select from the view.</p>
<p>•Use User Defined Datatypes if a particular column repeats in a lot of your tables, so that the datatype of that column is consistent across all your tables.</p>
<p>•Do not let your front-end applications query/manipulate the data directly using SELECT or INSERT/UPDATE/DELETE statements. Instead, create stored procedures, and let your applications access these stored procedures. This keeps the data access clean and consistent across all the modules of your application, and at the same time centralizing the business logic within the database.</p>
<p>•Try not to use TEXT or NTEXT datatypes for storing large textual data. The TEXT datatype has some inherent problems associated with it. For example, you cannot directly write or update text data using the INSERT or UPDATE statements. Instead,  you have to use special statements like READTEXT, WRITETEXT and UPDATETEXT. There are also a lot of bugs associated with replicating tables containing text columns. So, if you don&#8217;t have to store more than 8KB of text, use CHAR(8000) or VARCHAR(8000) datatypes instead.</p>
<p>•If you have a choice, do not store binary or image files (Binary Large Objects or BLOBs) inside the database. Instead, store the path to the binary or image file in the database and use that as a pointer to the actual binary file stored elsewhere on a server. Retrieving and manipulating these large binary files is better performed outside the database, and after all, a database is not meant for storing files.</p>
<p>•Use the CHAR data type for a column only when the column is non-nullable. If a CHAR column is nullable, it is treated as a fixed length column in SQL Server 7.0+. So, a CHAR(100), when NULL, will eat up 100 bytes, resulting in space wastage. So, use VARCHAR(100) in this situation. Of course, variable length columns do have a very little processing overhead over fixed length columns. Carefully choose between CHAR and VARCHAR depending up on the length of the data you are going to store.</p>
<p>•Avoid dynamic SQL statements as much as possible. Dynamic SQL tends to be slower than static SQL, as SQL Server must generate an execution plan every time at runtime. IF and CASE statements come in handy to avoid dynamic SQL. Another major disadvantage of using dynamic SQL is that it requires users to have direct access permissions on all accessed objects, like tables and views. Generally, users are given access to the stored procedures which reference the tables, but not directly on the tables. In this case, dynamic SQL will not work. Consider the following scenario where a user named &#8216;dSQLuser&#8217; is added to the pubs database and is granted access to a procedure named &#8216;dSQLproc&#8217;, but not on any other tables in the pubs database. The procedure dSQLproc executes a direct SELECT on titles table and that works. The second statement runs the same SELECT on titles table, using dynamic SQL and it fails with the following error:</p>
<p>Server: Msg 229, Level 14, State 5, Line 1<br />
SELECT permission denied on object &#8216;titles&#8217;, database &#8216;pubs&#8217;, owner &#8216;dbo&#8217;. </p>
<p>To reproduce the above problem, use the following commands:</p>
<p>sp_addlogin &#8216;dSQLuser&#8217;<br />
GO<br />
sp_defaultdb &#8216;dSQLuser&#8217;, &#8216;pubs&#8217;<br />
USE pubs<br />
GO<br />
sp_adduser &#8216;dSQLUser&#8217;, &#8216;dSQLUser&#8217;<br />
GO<br />
CREATE PROC dSQLProc<br />
AS<br />
BEGIN<br />
SELECT * FROM titles WHERE title_id = &#8216;BU1032&#8242; &#8211;This works<br />
DECLARE @str CHAR(100)<br />
SET @str = &#8216;SELECT * FROM titles WHERE title_id = &#8221;BU1032&#8221;&#8217;<br />
EXEC (@str) &#8211;This fails<br />
END<br />
GO<br />
GRANT EXEC ON dSQLProc TO dSQLuser<br />
GO </p>
<p>Now login to the pubs database using the login dSQLuser and execute the procedure dSQLproc to see the problem.</p>
<p>•Consider the following drawbacks before using the IDENTITY property for generating primary keys. IDENTITY is very much SQL Server specific, and you will have problems porting your database application to some other RDBMS. IDENTITY columns have other inherent problems. For example, IDENTITY columns can run out of numbers at some point, depending on the data type selected; numbers can&#8217;t be reused automatically, after deleting rows; and replication and IDENTITY columns don&#8217;t always get along well.<br />
So, come up with an algorithm to generate a primary key in the front-end or from within the inserting stored procedure. There still could be issues with generating your own primary keys too, like concurrency while generating the key, or running out of values. So, consider both options and go with the one that suits you best.</p>
<p>•Minimize the use of NULLs, as they often confuse the front-end applications, unless the applications are coded intelligently to eliminate NULLs or convert the NULLs into some other form. Any expression that deals with NULL results in a NULL output. ISNULL and COALESCE functions are helpful in dealing with NULL values. Here&#8217;s an example that explains the problem:</p>
<p>Consider the following table, Customers which stores the names of the customers and the middle name can be NULL.</p>
<p>CREATE TABLE Customers<br />
(<br />
FirstName varchar(20),<br />
MiddleName varchar(20),<br />
LastName varchar(20)<br />
) </p>
<p>Now insert a customer into the table whose name is Tony Blair, without a middle name:</p>
<p>INSERT INTO Customers<br />
(FirstName, MiddleName, LastName)<br />
VALUES (&#8216;Tony&#8217;,NULL,&#8217;Blair&#8217;)</p>
<p>The following SELECT statement returns NULL, instead of the customer name:</p>
<p>SELECT FirstName + &#8216; &#8216; + MiddleName + &#8216; &#8216; + LastName FROM Customers</p>
<p>To avoid this problem, use ISNULL as shown below:</p>
<p>SELECT FirstName + &#8216; &#8216; + ISNULL(MiddleName + &#8216; &#8216;,&#8221;) + LastName FROM Customers</p>
<p>•Use Unicode datatypes, like NCHAR, NVARCHAR, or NTEXT, if your database is going to store not just plain English characters, but a variety of characters used all over the world. Use these datatypes only when they are absolutely needed as they use twice as much space as non-Unicode datatypes.</p>
<p><a href="http://malleshv.wordpress.com/2009/08/18/sql-server-coding-best-practices-part2">ReadMore..</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/malleshv.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/malleshv.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/malleshv.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/malleshv.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/malleshv.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/malleshv.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/malleshv.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/malleshv.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/malleshv.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/malleshv.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/malleshv.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/malleshv.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/malleshv.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/malleshv.wordpress.com/45/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=malleshv.wordpress.com&amp;blog=7188786&amp;post=45&amp;subd=malleshv&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://malleshv.wordpress.com/2009/08/18/sql-server-coding-conventions-best-practices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e7643e7e288f6580f0387f37fe6598a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">malleshv</media:title>
		</media:content>
	</item>
		<item>
		<title>Multiple File Uploads in c# using Ajax</title>
		<link>http://malleshv.wordpress.com/2009/04/03/multiple-file-uploads-in-c-using-ajax/</link>
		<comments>http://malleshv.wordpress.com/2009/04/03/multiple-file-uploads-in-c-using-ajax/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 08:03:28 +0000</pubDate>
		<dc:creator>malleshv</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://malleshv.wordpress.com/?p=40</guid>
		<description><![CDATA[Ajax Uploader is an easy to use, hi-performance File Upload Control which allows you to upload files to web server without refreshing the page. It allows you select and upload multiple files and cancel running uploads, add new files during uploading. It supports AJAX frameworks and works in ajax updatepanel. Ajax Uploader allows you to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=malleshv.wordpress.com&amp;blog=7188786&amp;post=40&amp;subd=malleshv&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ajax Uploader is an easy to use, hi-performance File Upload Control which allows you to upload files to web server without refreshing the page.</p>
<p>It allows you select and upload multiple files and cancel running uploads, add new files during uploading. It supports AJAX frameworks and works in ajax updatepanel.</p>
<p>Ajax Uploader allows you to upload large files to a server with the low server memory consumption. The look and feel of file upload controls can be customized to seamlessly blend into your website design.</p>
<p>Refer the Links:</p>
<p><a href="http://ajaxuploader.com/"><br />
</a><a href="http://ajaxuploader.com/" target="_blank">AspUploader</a></p>
<p><a href="http://www.kodyaz.com/files/21/file_upload_sample_codes_and_sample_projects/entry336.aspx" target="_blank">Another Sample</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/malleshv.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/malleshv.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/malleshv.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/malleshv.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/malleshv.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/malleshv.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/malleshv.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/malleshv.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/malleshv.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/malleshv.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/malleshv.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/malleshv.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/malleshv.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/malleshv.wordpress.com/40/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=malleshv.wordpress.com&amp;blog=7188786&amp;post=40&amp;subd=malleshv&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://malleshv.wordpress.com/2009/04/03/multiple-file-uploads-in-c-using-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e7643e7e288f6580f0387f37fe6598a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">malleshv</media:title>
		</media:content>
	</item>
		<item>
		<title>WPF &#8211; Windows Presentation Foundation</title>
		<link>http://malleshv.wordpress.com/2009/04/02/wpf-windows-presentation-foundation/</link>
		<comments>http://malleshv.wordpress.com/2009/04/02/wpf-windows-presentation-foundation/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 08:04:10 +0000</pubDate>
		<dc:creator>malleshv</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://malleshv.wordpress.com/?p=28</guid>
		<description><![CDATA[Introduction to Windows Presentation Foundation Windows Presentation Foundation (WPF) is a next-generation presentation system for building Windows client applications with visually stunning user experiences. With WPF, you can create a wide range of both standalone and browser-hosted applications. Some examples are Yahoo! Messenger and the New York Times Reader, as well as the Contoso Healthcare Sample Application [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=malleshv.wordpress.com&amp;blog=7188786&amp;post=28&amp;subd=malleshv&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div class="title"><strong>Introduction to Windows Presentation Foundation</strong></div>
<p><!--Content type: Devdiv1. Transform: orcas2mtps.xslt.--></p>
<div class="introduction">
<p>Windows Presentation Foundation (WPF) is a next-generation presentation system for building Windows client applications with visually stunning user experiences. With WPF, you can create a wide range of both standalone and browser-hosted applications. Some examples are <span style="text-decoration:underline;">Yahoo! Messenger</span> and the <span style="text-decoration:underline;">New York Times Reader</span>, as well as the <span style="text-decoration:underline;">Contoso Healthcare Sample Application</span> that is shown in the following figure.</p>
<p><!--src=[../art/WPFIntroFigure24.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure24%28en-us,VS.90%29.png" alt="Contoso Healthcare UI sample" /></p>
<p>The core of WPF is a resolution-independent and vector-based rendering engine that is built to take advantage of modern graphics hardware. WPF extends the core with a comprehensive set of application-development features that include Extensible Application Markup Language (XAML), controls, data binding, layout, 2-D and 3-D graphics, animation, styles, templates, documents, media, text, and typography. WPF is included in the Microsoft .NET Framework, so you can build applications that incorporate other elements of the .NET Framework class library.</p>
<p>This overview is intended for newcomers and covers the key capabilities and concepts of WPF. Experienced WPF developers seeking a review of WPF may also find this overview useful.</p></div>
<p><a id="Programming_with_WPF"></a></p>
<div id="ctl00_rs1_mainContentContainer_cpe224597" class="MTPS_CollapsibleRegion">
<div id="ctl00_rs1_mainContentContainer_cpe224597_h" class="CollapseRegionLink"><strong><img class="LibC_o" style="vertical-align:middle;border-width:0;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Programming with WPF</strong></div>
<div class="CollapseRegionLink"><strong><br />
</strong></div>
<div id="ctl00_rs1_mainContentContainer_cpe224597_c" class="MTPS_CollapsibleSection" style="display:block;">
<ul>
<li>WPF exists as a subset of .NET Framework types that are for the most part located in the <span>System.Windows</span>namespace. If you have previously built applications with .NET Framework using managed technologies like ASP.NET and Windows Forms, the fundamental WPF programming experience should be familiar; you instantiate classes, set properties, call methods, and handle events, all using your favorite .NET Framework programming language, such as C# or Visual Basic.</li>
</ul>
<p>To support some of the more powerful WPF capabilities and to simplify the programming experience, WPF includes additional programming constructs that enhance properties and events: <span class="parameter">dependency properties</span> and <span class="parameter">routed events</span>.</div>
</div>
<p><a id="Markup_And_Codebehind"></a></p>
<div id="ctl00_rs1_mainContentContainer_cpe224598" class="MTPS_CollapsibleRegion">
<div id="ctl00_rs1_mainContentContainer_cpe224598_h" class="CollapseRegionLink"><strong><img class="LibC_o" style="vertical-align:middle;border-width:0;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Markup and Code-Behind</strong></div>
<div class="CollapseRegionLink"><strong><br />
</strong></div>
<blockquote>
<div id="ctl00_rs1_mainContentContainer_cpe224598_c" class="MTPS_CollapsibleSection" style="display:block;text-align:left;"><a id="sectionToggle1"></a>WPF offers additional programming enhancements for Windows client application development. One obvious enhancement is the ability to develop an application using both <span class="parameter">markup</span> and <span class="parameter">code-behind</span>, an experience that ASP.NET developers should be familiar with. You generally use Extensible Application Markup Language (XAML) markup to implement the appearance of an application while using managed programming languages (code-behind) to implement its behavior. This separation of appearance and behavior has the following benefits:</p>
<ul>
<li>Development and maintenance costs are reduced because appearance-specific markup is not tightly coupled with behavior-specific code.</li>
<li>Development is more efficient because designers can implement an application&#8217;s appearance simultaneously with developers who are implementing the application&#8217;s behavior.</li>
<li>Multiple design tools can be used to implement and share XAML markup, to target the requirements of the application development contributors; Microsoft Expression Blend provides an experience that suits designers, while Visual Studio 2005 targets developers.</li>
<li>Globalization and localization for WPF applications is greatly simplified</li>
</ul>
<h3 class="subHeading">Markup</h3>
<div class="subsection">
<p>XAML is an XML-based markup language that is used to implement an application&#8217;s appearance declaratively. It is typically used to create windows, dialog boxes, pages, and user controls, and to fill them with controls, shapes, and graphics.</p>
<p>The following example uses XAML to implement the appearance of a window that contains a single button.</p>
<div id="snippetGroup">
<div id="ctl00_rs1_mainContentContainer_ctl56_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl56XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;Window
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    Title=<span style="color:maroon;">"Window with Button"</span>
    Width=<span style="color:maroon;">"250"</span> Height=<span style="color:maroon;">"100"</span>&gt;

  &lt;!-- Add button <span style="color:blue;">to</span> window --&gt;
  &lt;Button Name=<span style="color:maroon;">"button"</span>&gt;Click <span style="color:blue;">Me</span>!&lt;/Button&gt;

&lt;/Window&gt;</pre>
</div>
</div>
</div>
<p>Specifically, this XAML defines a window and a button by using the <span><span class="input">Window</span></span> and <span><span class="input">Button</span></span> elements, respectively. Each element is configured with attributes, such as the <span><span class="input">Window</span></span> element&#8217;s <span><span class="input">Title</span></span> attribute to specify the window&#8217;s title-bar text. At run time, WPF converts the elements and attributes that are defined in markup to instances of WPF classes. For example, the <span><span class="input">Window</span></span> element is converted to an instance of the <span>Window</span> class whose <span>Title</span> property is the value of the <span><span class="input">Title</span></span> attribute.</p>
<p>The following figure shows the user interface (UI) that is defined by the XAML in the previous example.</p>
<p><!--src=[../art/WPFIntroFigure10.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure10%28en-us,VS.90%29.png" alt="A window that contains a button" /></p>
<p>Since XAML is XML-based, the UI that you compose with it is assembled in a hierarchy of nested elements known as an <span class="parameter">element tree</span>. The element tree provides a logical and intuitive way to create and manage UIs.</div>
<h3 class="subHeading">Code-Behind</h3>
<div class="subsection"></div>
</div>
</blockquote>
<blockquote><p>The main behavior of an application is to implement the functionality that responds to user interactions, including handling events (for example, clicking a menu, tool bar, or button) and calling business logic and data access logic in response. In WPF, this behavior is generally implemented in code that is associated with markup. This type of code is known as code-behind. The following example shows the code-behind and updated markup from the previous example.</p></blockquote>
<blockquote>
<div id="snippetGroup1">
<div id="ctl00_rs1_mainContentContainer_ctl62_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl62XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;Window
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
    x:Class=<span style="color:maroon;">"SDKSample.AWindow"</span>
    Title=<span style="color:maroon;">"Window with Button"</span>
    Width=<span style="color:maroon;">"250"</span> Height=<span style="color:maroon;">"100"</span>&gt;

  &lt;!-- Add button <span style="color:blue;">to</span> window --&gt;
  &lt;Button Name=<span style="color:maroon;">"button"</span> Click=<span style="color:maroon;">"button_Click"</span>&gt;Click <span style="color:blue;">Me</span>!&lt;/Button&gt;

&lt;/Window&gt;</pre>
</div>
</div>
</div>
<div id="snippetGroup2">
<div id="ctl00_rs1_mainContentContainer_ctl64_CSharp" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CodeDisplayLanguage">C#</div>
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl64CSharp');"><br />
</a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;"><span style="color:blue;">using</span> System.Windows; // Window, RoutedEventArgs, MessageBox

<span style="color:blue;">namespace</span> SDKSample
{
    <span style="color:blue;">public</span> partial <span style="color:blue;">class</span> AWindow : Window
    {
        <span style="color:blue;">public</span> AWindow()
        {
            <span style="color:green;">// InitializeComponent call is required to merge the UI</span>
            <span style="color:green;">// that is defined in markup with this class, including </span>
            <span style="color:green;">// setting properties and registering event handlers</span>
            InitializeComponent();
        }

        <span style="color:blue;">void</span> button_Click(object sender, RoutedEventArgs e)
        {
            <span style="color:green;">// Show message box when button is clicked</span>
            MessageBox.Show(<span style="color:maroon;"><span style="color:maroon;">"Hello, Windows Presentation Foundation!"</span></span>);
        }
    }
}</pre>
</div>
</div>
</div>
<p>In this example, the code-behind implements a class that derives from the <span>Window</span> class. The <span><span class="input">x:Class</span></span> attribute is used to associate the markup with the code-behind class. <span><span class="input">InitializeComponent</span></span> is called from the code-behind class&#8217;s constructor to merge the UI that is defined in markup with the code-behind class. (<span><span class="input">InitializeComponent</span></span> is generated for you when your application is built, which is why you don&#8217;t need to implement it manually.) The combination of <span><span class="input">x:Class</span></span> and <span><span class="input">InitializeComponent</span></span> ensure that your implementation is correctly initialized whenever it is created. The code-behind class also implements an event handler for the button&#8217;s <span>Click</span> event. When the button is clicked, the event handler shows a message box by calling the <span>MessageBox<span class="cs">.</span><span class="vb">.</span><span class="cpp">::</span><span class="nu">.</span>Show</span> method.</p>
<p>The following figure shows the result when the button is clicked.</p>
<p><!--src=[../art/WPFIntroFigure25.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure25%28en-us,VS.90%29.png" alt="A MessageBox" /></p></blockquote>
</div>
<p><a id="Applications"></a></p>
<div id="ctl00_rs1_mainContentContainer_cpe224599" class="MTPS_CollapsibleRegion">
<div id="ctl00_rs1_mainContentContainer_cpe224599_h" class="CollapseRegionLink"><strong><img class="LibC_o" style="vertical-align:middle;border-width:0;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Applications</strong></div>
<blockquote>
<div id="ctl00_rs1_mainContentContainer_cpe224599_c" class="MTPS_CollapsibleSection" style="display:block;">.NET Framework, <span>System.Windows</span>, and markup and code-behind, constitute the foundation of the WPF application development experience. Additionally, WPF has comprehensive features for creating user experiences with rich content. To package this content and deliver it to users as &#8220;applications,&#8221; WPF provides types and services that are collectively known as the <span class="parameter">application model</span>. The application model supports the development of both standalone and browser-hosted applications.</p>
<h3 class="subHeading">Standalone Applications</h3>
<div class="subsection">
<p>For standalone applications, you can use the <span>Window</span> class to create windows and dialog boxes that are accessed from menu bars and tool bars. The following figure shows a standalone application with a main window and a dialog box.</p>
<p><!--src=[../art/WPFIntroFigure26.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure26%28en-us,VS.90%29.png" alt="A main window and a dialog box" /></p>
<p>Additionally, you can use the following WPF dialog boxes: <span>MessageBox</span>, <span>OpenFileDialog</span>, <span>SaveFileDialog</span>, and <span>PrintDialog</span>.</div>
<h3 class="subHeading">Browser-Hosted Applications</h3>
<div class="subsection">
<p>For browser-hosted applications, known as XAML browser applications (XBAPs), you can create pages (<span>Page</span>) and page functions (<span>PageFunction<span class="cs">&lt;</span><span class="vb">(Of </span><span class="cpp">&lt;</span><span class="nu">(</span>T<span class="cs">&gt;</span><span class="vb">)</span><span class="cpp">&gt;</span><span class="nu">)</span></span>) that you can navigate between using hyperlinks (<span>Hyperlink</span> classes). The following figure shows a page in an XBAP that is hosted in Internet Explorer 7.</p>
<p><!--src=[../art/WPFIntroFigure27.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure27%28en-us,VS.90%29.png" alt="Two pages of a hosted application" />WPF applications can be hosted in both Microsoft Internet Explorer 6 and Internet Explorer 7. WPF offers the two following options for alternative navigation hosts:</p>
<ul>
<li><span>Frame</span>, to host islands of navigable content in either pages or windows.</li>
<li><span>NavigationWindow</span>, to host navigable content in an entire window.</li>
</ul>
</div>
<h3 class="subHeading">The Application Class</h3>
<div class="subsection">
<p>Both XBAPs and standalone applications are often complex enough to require additional application-scoped services, including startup and lifetime management, shared properties, and shared resources. The <span>Application</span> class encapsulates these services and more, and it can be implemented by just using XAML, as shown in the following example.</p>
<div id="snippetGroup3">
<div id="ctl00_rs1_mainContentContainer_ctl117_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl117XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;Application
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    StartupUri=<span style="color:maroon;">"MainWindow.xaml"</span> /&gt;</pre>
</div>
</div>
</div>
<p>This markup is the <span class="parameter">application definition</span> for a standalone application, and instructs WPF to create an <span>Application</span> object that automatically opens <span>MainWindow</span> when the application is started.</p>
<p>A key concept to understand about <span>Application</span> is that it provides a common platform of support for both standalone and browser-hosted applications. For example, the preceding XAML could be used by a browser-hosted application to automatically navigate to a page when an XBAP is started, as shown in the following example.</p>
<div id="snippetGroup4">
<div id="ctl00_rs1_mainContentContainer_ctl121_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl121XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;Application
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    StartupUri=<span style="color:maroon;">"HomePage.xaml"</span> /&gt;</pre>
</div>
</div>
</div>
</div>
<h3 class="subHeading">Security</h3>
<div class="subsection">
<p>Because XBAPs are hosted in a browser, security is important. In particular, a partial-trust security sandbox is used by XBAPs to enforce restrictions that are less than or equal to the restrictions imposed on HTML-based applications. Furthermore, each HTML feature that is safe to run from XBAPs in partial trust has been tested using a comprehensive security process</p>
<p>Still, a majority of WPF features can be safely executed from XBAPs.</p></div>
</div>
</blockquote>
</div>
<p><a id="Controls"></a></p>
<div id="ctl00_rs1_mainContentContainer_cpe224600" class="MTPS_CollapsibleRegion">
<div id="ctl00_rs1_mainContentContainer_cpe224600_h" class="CollapseRegionLink"><strong><img class="LibC_o" style="vertical-align:middle;border-width:0;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Controls</strong></div>
<blockquote>
<div id="ctl00_rs1_mainContentContainer_cpe224600_c" class="MTPS_CollapsibleSection" style="display:block;"><a id="sectionToggle3"></a>The user experiences that are delivered by the application model are constructed controls. In WPF, &#8220;control&#8221; is an umbrella term that applies to a category of WPF classes that are hosted in either a window or a page, have a user interface (UI), and implement some behavior.</p>
<h3 class="subHeading">WPF Control Roll Call</h3>
<div class="subsection">
<p>The built-in WPF controls are listed here.</p>
<ul>
<li><span class="label">Buttons</span>: <span>Button</span> and <span>RepeatButton</span>.</li>
<li><span class="label">Dialog Boxes</span>: <span>OpenFileDialog</span>, <span>PrintDialog</span>, and <span>SaveFileDialog</span>.</li>
<li><span class="label">Digital Ink</span>: <span>InkCanvas</span> and <span>InkPresenter</span>.</li>
<li><span class="label">Documents</span>: <span>DocumentViewer</span>, <span>FlowDocumentPageViewer</span>, <span>FlowDocumentReader</span>, <span>FlowDocumentScrollViewer</span>, and <span>StickyNoteControl</span>.</li>
<li><span class="label">Input</span>: <span>TextBox</span>, <span>RichTextBox</span>, and <span>PasswordBox</span>.</li>
<li><span class="label">Layout</span>: <span>Border</span>, <span>BulletDecorator</span>, <span>Canvas</span>, <span>DockPanel</span>, <span>Expander</span>, <span>Grid</span>, <span>GridView</span>, <span>GridSplitter</span>, <span>GroupBox</span>, <span>Panel</span>, <span>ResizeGrip</span>, <span>Separator</span>, <span>ScrollBar</span>, <span>ScrollViewer</span>, <span>StackPanel</span>, <span>Thumb</span>, <span>Viewbox</span>, <span>VirtualizingStackPanel</span>, <span>Window</span>, and <span>WrapPanel</span>.</li>
<li><span class="label">Media</span>: <span>Image</span>, <span>MediaElement</span>, and <span>SoundPlayerAction</span>.</li>
<li><span class="label">Menus</span>: <span>ContextMenu</span>, <span>Menu</span>, and <span>ToolBar</span>.</li>
<li><span class="label">Navigation</span>: <span>Frame</span>, <span>Hyperlink</span>, <span>Page</span>, <span>NavigationWindow</span>, and <span>TabControl</span>.</li>
<li><span class="label">Selection</span>: <span>CheckBox</span>, <span>ComboBox</span>, <span>ListBox</span>, <span>TreeView</span>, and <span>RadioButton</span>, <span>Slider</span>.</li>
<li><span class="label">User Information</span>: <span>AccessText</span>, <span>Label</span>, <span>Popup</span>, <span>ProgressBar</span>, <span>StatusBar</span>, <span>TextBlock</span>, and <span>ToolTip</span>.</li>
</ul>
</div>
</div>
</blockquote>
</div>
<p><a id="Input_And_Commanding"></a></p>
<div id="ctl00_rs1_mainContentContainer_cpe224601" class="MTPS_CollapsibleRegion">
<div id="ctl00_rs1_mainContentContainer_cpe224601_h" class="CollapseRegionLink"><strong><img class="LibC_o" style="vertical-align:middle;border-width:0;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Input and Commanding</strong></div>
<blockquote>
<div id="ctl00_rs1_mainContentContainer_cpe224601_c" class="MTPS_CollapsibleSection" style="display:block;">Controls most often detect and respond to user input. The WPF input system uses both direct and routed events to support text input, focus management, and mouse positioning.<br />
Applications often have complex input requirements. WPF provides a command system that separates user input actions from the code that responds to those actions.</div>
</blockquote>
</div>
<p><a id="Layout"></a></p>
<div id="ctl00_rs1_mainContentContainer_cpe224602" class="MTPS_CollapsibleRegion">
<div id="ctl00_rs1_mainContentContainer_cpe224602_h" class="CollapseRegionLink"><strong><img class="LibC_o" style="vertical-align:middle;border-width:0;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Layout</strong></div>
<blockquote>
<div id="ctl00_rs1_mainContentContainer_cpe224602_c" class="MTPS_CollapsibleSection" style="display:block;"><a id="sectionToggle5"></a>When you create a UI, you arrange your controls by location and size to form a layout. A key requirement of any layout is to adapt to changes in window size and display settings. Rather than forcing you to write the code to adapt a layout in these circumstances, WPF provides a first-class, extensible layout system for you.The cornerstone of the layout system is relative positioning, which increases the ability to adapt to changing window and display conditions. In addition, the layout system manages the negotiation between controls to determine the layout. The negotiation is a two-step process: first, a control tells its parent what location and size it requires; second, the parent tells the control what space it can have.</p>
<ul>
<li><span>Canvas</span>: Child controls provide their own layout.</li>
<li><span>DockPanel</span>: Child controls are aligned to the edges of the panel.</li>
<li><span>Grid</span>: Child controls are positioned by rows and columns.</li>
<li><span>StackPanel</span>: Child controls are stacked either vertically or horizontally.</li>
<li><span>VirtualizingStackPanel</span>: Child controls are virtualized and arranged on a single line that is either horizontally or vertically oriented.</li>
<li><span>WrapPanel</span>: Child controls are positioned in left-to-right order and wrapped to the next line when there are more controls on the current line than space allows.</li>
</ul>
<div id="snippetGroup5">
<div id="ctl00_rs1_mainContentContainer_ctl283_XAML" class="libCScode">
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;Window
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
    x:Class=<span style="color:maroon;">"SDKSample.LayoutWindow"</span>
    Title=<span style="color:maroon;">"Layout with the DockPanel"</span> Height=<span style="color:maroon;">"143"</span> Width=<span style="color:maroon;">"319"</span>&gt;

  &lt;!--DockPanel <span style="color:blue;">to</span> layout four text boxes--&gt;
  &lt;DockPanel&gt;
    &lt;TextBox DockPanel.Dock=<span style="color:maroon;">"Top"</span>&gt;Dock = <span style="color:maroon;">"Top"</span>&lt;/TextBox&gt;
    &lt;TextBox DockPanel.Dock=<span style="color:maroon;">"Bottom"</span>&gt;Dock = <span style="color:maroon;">"Bottom"</span>&lt;/TextBox&gt;
    &lt;TextBox DockPanel.Dock=<span style="color:maroon;">"Left"</span>&gt;Dock = <span style="color:maroon;">"Left"</span>&lt;/TextBox&gt;
    &lt;TextBox Background=<span style="color:maroon;">"White"</span>&gt;This TextBox <span style="color:maroon;">"fills"</span> the remaining space.&lt;/TextBox&gt;
  &lt;/DockPanel&gt;

&lt;/Window&gt;</pre>
</div>
</div>
</div>
<p>The <span>DockPanel</span> allows the child <span>TextBox</span> controls to tell it how to arrange them. To do this, the <span>DockPanel</span> implements a <span>Dock</span> property that is exposed to the child controls to allow each of them to specify a dock style.</p>
<div class="alert">
<table style="height:48px;" border="0" width="10">
<tbody>
<tr>
<th></th>
</tr>
<tr>
<td></td>
</tr>
</tbody>
</table>
</div>
<p>The following figure shows the result of the XAML markup in the preceding example.</p>
<p><!--src=[../art/WPFIntroFigure11.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure11%28en-us,VS.90%29.png" alt="DockPanel page" /></div>
<p>The layout system is exposed to child controls through base WPF classes. For common layouts such as grids, stacking, and docking, WPF includes several layout controls:</p></blockquote>
</div>
<p><a id="Data_Binding"></a></p>
<div id="ctl00_rs1_mainContentContainer_cpe224603" class="MTPS_CollapsibleRegion">
<div id="ctl00_rs1_mainContentContainer_cpe224603_h" class="CollapseRegionLink"><strong><img class="LibC_o" style="vertical-align:middle;border-width:0;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Data Binding</strong></div>
<blockquote>
<div id="ctl00_rs1_mainContentContainer_cpe224603_c" class="MTPS_CollapsibleSection" style="display:block;"><a id="sectionToggle6"></a>Most applications are created to provide users with the means to view and edit data. For WPF applications, the work of storing and accessing data is already provided for by technologies such as Microsoft SQL Server and ADO.NET. After the data is accessed and loaded into an application&#8217;s managed objects, the hard work for WPF applications begins. Essentially, this involves two things:</p>
<ol>
<li>Copying the data from the managed objects into controls, where the data can be displayed and edited.</li>
<li>Ensuring that changes made to data by using controls are copied back to the managed objects.</li>
</ol>
<p>To simplify application development, WPF provides a data binding engine to automatically perform these steps. The core unit of the data binding engine is the <span>Binding</span> class, whose job is to bind a control (the binding target) to a data object (the binding source). This relationship is illustrated by the following figure.</p>
<p><!--src=[../art/DataBindingMostBasic.png]--><img src="http://i.msdn.microsoft.com/Aa970268.DataBindingMostBasic%28en-us,VS.90%29.png" alt="Basic data binding diagram" /></p>
<p>The following example demonstrates how to bind a <span>TextBox</span> to an instance of a custom <span class="code">Person</span> object. The <span class="code">Person</span> implementation is shown in the following code.</p>
<div id="snippetGroup6">
<div id="ctl00_rs1_mainContentContainer_ctl314_CSharp" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CodeDisplayLanguage">C#</div>
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl314CSharp');"><br />
</a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;"><span style="color:blue;">namespace</span> SDKSample
{
    <span style="color:blue;">class</span> Person
    {
        <span style="color:blue;">string</span> name = <span style="color:maroon;"><span style="color:maroon;">"No Name"</span></span>;

        <span style="color:blue;">public</span> <span style="color:blue;">string</span> Name
        {
            <span style="color:blue;">get</span> { <span style="color:blue;">return</span> name; }
            <span style="color:blue;">set</span> { name = value; }
        }
    }
}</pre>
</div>
</div>
</div>
<p>The following markup binds the <span>TextBox</span> to an instance of a custom <span class="code">Person</span> object.</p>
<div id="snippetGroup7">
<div id="ctl00_rs1_mainContentContainer_ctl316_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl316XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;Window
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
    x:Class=<span style="color:maroon;">"SDKSample.DataBindingWindow"</span>&gt;

...

&lt;!-- Bind the TextBox <span style="color:blue;">to</span> the data source (TextBox.Text <span style="color:blue;">to</span> Person.Name) --&gt;
&lt;TextBox Name=<span style="color:maroon;">"personNameTextBox"</span> Text=<span style="color:maroon;">"{Binding Path=Name}"</span> /&gt;

...

&lt;/Window&gt;</pre>
</div>
</div>
</div>
<div id="snippetGroup8">
<div id="ctl00_rs1_mainContentContainer_ctl318_CSharp" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CodeDisplayLanguage">C#</div>
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl318CSharp');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;"><span style="color:blue;">using</span> System.Windows; // Window

<span style="color:blue;">namespace</span> SDKSample
{
    <span style="color:blue;">public</span> partial <span style="color:blue;">class</span> DataBindingWindow : Window
    {
        <span style="color:blue;">public</span> DataBindingWindow()
        {
            InitializeComponent();

            <span style="color:green;">// Create Person data source</span>
            Person person = <span style="color:blue;">new</span> Person();

            <span style="color:green;">// Make data source available for binding</span>
            <span style="color:blue;">this</span>.DataContext = person;
        }
    }
}</pre>
</div>
</div>
</div>
<p>In this example, the <span class="code">Person</span> class is instantiated in code-behind and is set as the data context for the <span class="code">DataBindingWindow</span>. In markup, the <span>Text</span> property of the <span>TextBox</span> is bound to the <span class="code">Person.Name</span> property (using the &#8220;<span class="code">{Binding &#8230; }</span>&#8221; XAML syntax). This XAML tells WPF to bind the <span>TextBox</span> control to the <span class="code">Person</span> object that is stored in the <span>DataContext</span> property of the window.</p>
<p>The WPF data binding engine provides additional support that includes validation, sorting, filtering, and grouping. Furthermore, data binding supports the use of data templates to create custom UI for bound data when the UI displayed by the standard WPF controls is not appropriate.</p></div>
</blockquote>
</div>
<p><a id="Graphics"></a></p>
<div id="ctl00_rs1_mainContentContainer_cpe224604" class="MTPS_CollapsibleRegion">
<div id="ctl00_rs1_mainContentContainer_cpe224604_h" class="CollapseRegionLink"><strong><img class="LibC_o" style="vertical-align:middle;border-width:0;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Graphics</strong></div>
<blockquote>
<div id="ctl00_rs1_mainContentContainer_cpe224604_c" class="MTPS_CollapsibleSection" style="display:block;"><a id="sectionToggle7"></a>WPF introduces an extensive, scalable, and flexible set of graphics features that have the following benefits:</p>
<ul>
<li><span class="label">Resolution-independent and device-independent graphics</span>. The basic unit of measurement in the WPF graphics system is the device independent pixel, which is 1/96th of an inch, regardless of actual screen resolution, and provides the foundation for resolution-independent and device-independent rendering. Each device-independent pixel automatically scales to match the dots-per-inch (dpi) setting of the system it renders on.</li>
<li><span class="label">Improved precision</span>. The WPF coordinate system is measured with double-precision floating-point numbers rather than single-precision. Transformations and opacity values are also expressed as double-precision. WPF also supports a wide color gamut (scRGB) and provides integrated support for managing inputs from different color spaces.</li>
<li><span class="label">Advanced graphics and animation support</span>. WPF simplifies graphics programming by managing animation scenes for you; there is no need to worry about scene processing, rendering loops, and bilinear interpolation. Additionally, WPF provides hit-testing support and full alpha-compositing support.</li>
<li><span class="label">Hardware acceleration</span>. The WPF graphics system takes advantage of graphics hardware to minimize CPU usage.</li>
</ul>
<h3 class="subHeading">2-D Shapes</h3>
<div class="subsection">
<p>WPF provides a library of common vector-drawn 2-D shapes, such as the rectangles and ellipses that are shown in the following illustration.</p>
<p><!--src=[../art/WPFIntroFigure4.PNG]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure4%28en-us,VS.90%29.png" alt="Ellipses and rectangles" />An interesting capability of shapes is that they are not just for display; shapes implement many of the features that you expect from controls, including keyboard and mouse input. The following example shows the <span>MouseUp</span> event of an <span>Ellipse</span> being handled.</p>
<div id="snippetGroup9">
<div id="ctl00_rs1_mainContentContainer_ctl350_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl350XAML');"><img class="LibC_copy_off" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" border="0" alt="" height="9" align="middle" /></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;Window
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
    x:Class=<span style="color:maroon;">"SDKSample.EllipseEventHandlingWindow"</span>
    Title=<span style="color:maroon;">"Click the Ellipse"</span>&gt;
    &lt;Ellipse Name=<span style="color:maroon;">"clickableEllipse"</span> Fill=<span style="color:maroon;">"Blue"</span> MouseUp=<span style="color:maroon;">"clickableEllipse_MouseUp"</span> /&gt;
&lt;/Window&gt;</pre>
</div>
</div>
</div>
<div id="snippetGroup10">
<div id="ctl00_rs1_mainContentContainer_ctl352_CSharp" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CodeDisplayLanguage">C#</div>
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl352CSharp');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;"><span style="color:blue;">using</span> System.Windows; // Window, MessageBox
<span style="color:blue;">using</span> System.Windows.Input; // MouseButtonEventHandler

<span style="color:blue;">namespace</span> SDKSample
{
    <span style="color:blue;">public</span> partial <span style="color:blue;">class</span> EllipseEventHandlingWindow : Window
    {
        <span style="color:blue;">public</span> EllipseEventHandlingWindow()
        {
            InitializeComponent();
        }

        <span style="color:blue;">void</span> clickableEllipse_MouseUp(object sender, MouseButtonEventArgs e)
        {
            <span style="color:green;">// Display a message</span>
            MessageBox.Show(<span style="color:maroon;"><span style="color:maroon;">"You clicked the ellipse!"</span></span>);
        }
    }
}</pre>
</div>
</div>
</div>
<p>The following figure shows what is produced by the preceding code.</p>
<p><!--src=[../art/WPFIntroFigure12.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure12%28en-us,VS.90%29.png" alt="A window with the text " /></div>
<h3 class="subHeading">2-D Geometries</h3>
<div class="subsection">
<p>The 2-D shapes provided by WPF cover the standard set of basic shapes. However, you may need to create custom shapes to facilitate the design of a customized UI. For this purpose, WPF provides geometries. The following figure demonstrates the use of geometries to create a custom shape that can be drawn directly, used as a brush, or used to clip other shapes and controls.</p>
<p><span>Path</span> objects can be used to draw closed or open shapes, multiple shapes, and even curved shapes.</p>
<p><span>Geometry</span> objects can be used for clipping, hit-testing, and rendering 2-D graphic data.</p>
<p><!--src=[../art/WPFIntroFigure5.PNG]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure5%28en-us,VS.90%29.png" alt="Various uses of a Path" /></div>
<h3 class="subHeading">2-D Effects</h3>
<div class="subsection">
<p>A subset of WPF 2-D capabilities includes visual effects, such as gradients, bitmaps, drawings, painting with videos, rotation, scaling, and skewing. These are all achieved with brushes; the following figure shows some examples.</p>
<p><!--src=[../art/WPFIntroFigure6.PNG]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure6%28en-us,VS.90%29.png" alt="Illustration of different brushes" /></div>
<h3 class="subHeading">3-D Rendering</h3>
<div class="subsection">
<p>WPF also includes 3-D rendering capabilities that integrate with 2-D graphics to allow the creation of more exciting and interesting UIs. For example, the following figure shows 2-D images rendered onto 3-D shapes.</p>
<p><!--src=[../art/WPFIntroFigure13.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure13%28en-us,VS.90%29.png" alt="Visual3D sample screen shot" /></div>
</div>
</blockquote>
</div>
<p><a id="Animation"></a></p>
<div id="ctl00_rs1_mainContentContainer_cpe224605" class="MTPS_CollapsibleRegion">
<div id="ctl00_rs1_mainContentContainer_cpe224605_h" class="CollapseRegionLink"><strong><img class="LibC_o" style="vertical-align:middle;border-width:0;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Animation</strong></div>
<blockquote>
<div id="ctl00_rs1_mainContentContainer_cpe224605_c" class="MTPS_CollapsibleSection" style="display:block;"><a id="sectionToggle8"></a>WPF animation support lets you make controls grow, shake, spin, and fade, to create interesting page transitions, and more. You can animate most WPF classes, even custom classes. The following figure shows a simple animation in action.<!--src=[../art/WPFIntroFigure7.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure7%28en-us,VS.90%29.png" alt="Images of an animated cube" /></div>
</blockquote>
</div>
<p><a id="Media"></a></p>
<div id="ctl00_rs1_mainContentContainer_cpe224606" class="MTPS_CollapsibleRegion">
<div id="ctl00_rs1_mainContentContainer_cpe224606_h" class="CollapseRegionLink"><strong><img class="LibC_o" style="vertical-align:middle;border-width:0;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Media</strong></div>
<blockquote>
<div id="ctl00_rs1_mainContentContainer_cpe224606_c" class="MTPS_CollapsibleSection" style="display:block;"><a id="sectionToggle9"></a>One way to convey rich content is through the use of audiovisual media. WPF provides special support for images, video, and audio.</p>
<h3 class="subHeading">Images</h3>
<div class="subsection">
<p>Images are common to most applications, and WPF provides several ways to use them. The following figure shows a UI with a list box that contains thumbnail images. When a thumbnail is selected, the image is shown full-size.</p>
<p><!--src=[../art/WPFIntroFigure8.PNG]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure8%28en-us,VS.90%29.png" alt="Thumbnail images and a full-size image" /></div>
<h3 class="subHeading">Video and Audio</h3>
<div class="subsection">
<p>The <span>MediaElement</span> control is capable of playing both video and audio, and it is flexible enough to be the basis for a custom media player. The following XAML markup implements a media player.</p>
<div id="snippetGroup11">
<div id="ctl00_rs1_mainContentContainer_ctl390_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl390XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;MediaElement
  Name=<span style="color:maroon;">"myMediaElement"</span>
  Source=<span style="color:maroon;">"media/wpf.wmv"</span>
  LoadedBehavior=<span style="color:maroon;">"Manual"</span>
  Width=<span style="color:maroon;">"350"</span> Height=<span style="color:maroon;">"250"</span> /&gt;</pre>
</div>
</div>
</div>
<p>The window in the following figure shows the <span><a id="ctl00_rs1_mainContentContainer_ctl391" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement.aspx">MediaElement</a></span> control in action.</p>
<p><!--src=[../art/WPFIntroFigure1.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure1%28en-us,VS.90%29.png" alt="A MediaElement control with audio and video" /></div>
</div>
</blockquote>
</div>
<p><a id="Text_and_Typography"></a></p>
<div id="ctl00_rs1_mainContentContainer_cpe224607" class="MTPS_CollapsibleRegion">
<div id="ctl00_rs1_mainContentContainer_cpe224607_h" class="CollapseRegionLink"><strong><img class="LibC_o" style="vertical-align:middle;border-width:0;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Text and Typography</strong></div>
<blockquote>
<div id="ctl00_rs1_mainContentContainer_cpe224607_c" class="MTPS_CollapsibleSection" style="display:block;"><a id="sectionToggle10"></a>To facilitate high-quality text rendering, WPF offers the following features:</p>
<ul>
<li>OpenType font support.</li>
<li>ClearType enhancements.</li>
<li>High performance that takes advantage of hardware acceleration.</li>
<li>Integration of text with media, graphics, and animation.</li>
<li>International font support and fallback mechanisms.</li>
</ul>
<p>As a demonstration of text integration with graphics, the following figure shows the application of text decorations.</p>
<p><!--src=[../art/WPFIntroFigure23.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure23%28en-us,VS.90%29.png" alt="Text with various text decorations" /></div>
</blockquote>
</div>
<p><a id="Documents"></a></p>
<div id="ctl00_rs1_mainContentContainer_cpe224608" class="MTPS_CollapsibleRegion">
<div id="ctl00_rs1_mainContentContainer_cpe224608_h" class="CollapseRegionLink"><strong><img class="LibC_o" style="vertical-align:middle;border-width:0;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Documents</strong></div>
<blockquote>
<div id="ctl00_rs1_mainContentContainer_cpe224608_c" class="MTPS_CollapsibleSection" style="display:block;"><a id="sectionToggle11"></a>WPF has native support for working with three types of documents: flow documents, fixed documents, and XML Paper Specification (XPS) documents. WPF also provides the services to create, view, manage, annotate, package, and print documents.</p>
<h3 class="subHeading">Flow Documents</h3>
<div class="subsection">
<p>Flow documents are designed to optimize viewing and readability by dynamically adjusting and reflowing content when window size and display settings change. The following XAML markup shows the definition of a <span>FlowDocument</span>.</p>
<div id="snippetGroup12">
<div id="ctl00_rs1_mainContentContainer_ctl433_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl433XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;FlowDocument xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>&gt;

  &lt;Paragraph FontSize=<span style="color:maroon;">"18"</span> FontWeight=<span style="color:maroon;">"Bold"</span>&gt;Flow Document&lt;/Paragraph&gt;

  &lt;Paragraph&gt;
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
    nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi
    enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis
    nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure.
  &lt;/Paragraph&gt;

...

&lt;/FlowDocument&gt;</pre>
</div>
</div>
</div>
<p>The following example demonstrates how to load a flow document into a <span>FlowDocumentReader</span> for viewing, searching, and printing.</p>
<div id="snippetGroup13">
<div id="ctl00_rs1_mainContentContainer_ctl435_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl435XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;Window
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
    x:Class=<span style="color:maroon;">"SDKSample.FlowDocumentReaderWindow"</span>
    Title=<span style="color:maroon;">"Flow Document Reader"</span>&gt;
  &lt;FlowDocumentReader Name=<span style="color:maroon;">"flowDocumentReader"</span> /&gt;
&lt;/Window&gt;</pre>
</div>
</div>
</div>
<div id="snippetGroup14">
<div id="ctl00_rs1_mainContentContainer_ctl437_CSharp" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CodeDisplayLanguage">C#</div>
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl437CSharp');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;"><span style="color:blue;">using</span> System.Windows; // Window
<span style="color:blue;">using</span> System.Windows.Documents; // FlowDocument
<span style="color:blue;">using</span> System.IO; // FileStream, FileMode
<span style="color:blue;">using</span> System.Windows.Markup; // XamlReader

<span style="color:blue;">namespace</span> SDKSample
{
    <span style="color:blue;">public</span> partial <span style="color:blue;">class</span> FlowDocumentReaderWindow : System.Windows.Window
    {
        <span style="color:blue;">public</span> FlowDocumentReaderWindow()
        {
            InitializeComponent();

            <span style="color:green;">// Open the file that contains the FlowDocument</span>
            <span style="color:blue;">using</span> (FileStream xamlFile = <span style="color:blue;">new</span> FileStream(<span style="color:maroon;"><span style="color:maroon;">"AFlowDocument.xaml"</span></span>,
                FileMode.Open, FileAccess.Read))
            {
                <span style="color:green;">// Parse the file with the XamlReader.Load method</span>
                FlowDocument content = XamlReader.Load(xamlFile) as FlowDocument;

                <span style="color:green;">// Set the Document property to the parsed FlowDocument object</span>
                <span style="color:blue;">this</span>.flowDocumentReader.Document = content;
            }
        }
    }
}</pre>
</div>
</div>
</div>
<p>The following example shows the result.</p>
<p><!--src=[../art/WPFIntroFigure17.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure17%28en-us,VS.90%29.png" alt="A FlowDocument within a FlowDocumentReader control" />F</div>
<h3 class="subHeading">Fixed Documents</h3>
<div class="subsection">
<p>Fixed documents are intended for applications that require a precise &#8220;what you see is what you get&#8221; (WYSIWYG) presentation, particularly with respect to printing. Typical uses for fixed documents include desktop publishing, word processing, and form layout, where adherence to the original page design is critical.</p>
<p>Fixed documents maintain the precise arrangement of their content in a device-independent manner. For example, a fixed document that is displayed on a 96 dots-per-inch (dpi) display appears the same as when it is printed to either a 600 dpi laser printer or a 4800 dpi photo typesetter. The layout remains the same in all cases, although the document&#8217;s quality varies depending on the capabilities of each device.</p></div>
<h3 class="subHeading">XPS Documents</h3>
<div class="subsection">
<p>XML Paper Specification (XPS) documents build on WPF&#8217;s fixed documents. XPS documents are described with an XML-based schema that is essentially a paginated representation of electronic paper. XPS is an open, cross-platform document format that is designed to facilitate the creation, sharing, printing, and archiving of paginated documents. Important features of the XPS technology include the following:</p>
<ul>
<li>Packaging of XPS documents as <span>ZipPackage</span> files that conform to the Open Packaging Conventions (OPC).</li>
<li>Hosting in both standalone and browser-based applications.</li>
<li>Manual generation and manipulation of XPS documents from WPF applications.</li>
<li>High-fidelity rendering by targeting maximum output device quality.</li>
<li>Windows Vista print spooling.</li>
<li>Direct routing of documents to XPS-compatible printers.</li>
<li>UI integration with <span>DocumentViewer</span>.</li>
</ul>
<p>The following figure shows an XPS document that is displayed by a <span>DocumentViewer</span>.</p>
<p><!--src=[../art/WPFIntroFigure15.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure15%28en-us,VS.90%29.png" alt="An XPS document within a DocumentViewer control" /><span><a id="ctl00_rs1_mainContentContainer_ctl447" href="http://msdn.microsoft.com/en-us/library/system.windows.controls.documentviewer.aspx"></a></span></div>
<h3 class="subHeading">Annotations</h3>
<div class="subsection">
<p>Annotations are notes or comments that are added to documents to flag information or to highlight items of interest for later reference. Although writing notes on printed documents is easy, the ability to &#8220;write&#8221; notes on electronic documents is often limited or unavailable. In WPF, however, an annotations system is provided to support sticky notes and highlights. Additionally, these annotations can be applied to documents hosted in the <span>DocumentViewer</span> control, as shown in the following figure.</p>
<p><!--src=[../art/WPFIntroFigure16.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure16%28en-us,VS.90%29.png" alt="Annotation styling" /></div>
<h3 class="subHeading">Packaging</h3>
<div class="subsection">
<p>The WPF <span>System.IO.Packaging</span> APIs allow your applications to organize data, content, and resources into single, portable, easy-to-distribute, and easy-to-access ZIP documents. Digital signatures can be included to authenticate items that are contained in a package and to verify that the signed item was not tampered with or modified. You can also encrypt packages by using rights management in order to restrict access to protected information.</div>
<h3 class="subHeading">Printing</h3>
<div class="subsection">
<p>The .NET Framework includes a printing subsystem that WPF augments with support for enhanced print system control. Printing enhancements include the following:</p>
<ul>
<li>Real-time installation of remote print servers and queues.</li>
<li>Dynamic discovery of printer capabilities.</li>
<li>Dynamic setting of printer options.</li>
<li>Print job rerouting and reprioritizing.</li>
</ul>
<p>XPS documents also have a key performance enhancement. The existing Microsoft Windows Graphics Device Interface (GDI) print path typically requires two conversions:</p>
<ul>
<li>The first conversion of a document into a print processor format, such as Enhanced Metafile (EMF).</li>
<li>A second conversion into the page description language of the printer, such as Printer Control Language (PCL) or PostScript.</li>
</ul>
<p>However, XPS documents avoid these conversions because one component of the XPS file format is a print processor language and a page description language. This support helps to reduce both spool file size and networked printer loads.</p></div>
</div>
</blockquote>
</div>
<p><a id="WPF_Customization"></a></p>
<div id="ctl00_rs1_mainContentContainer_cpe224609_h" class="CollapseRegionLink"><strong><img class="LibC_o" style="vertical-align:middle;border-width:0;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" alt="" /> Customizing WPF Applications</strong></div>
<p><a id="sectionToggle12"></a></p>
<p>Up to this point, you&#8217;ve seen the core WPF building blocks for developing applications. You use the application model to host and deliver application content, which consists mainly of controls. To simplify the arrangement of controls in a UI, and to ensure the arrangement is maintained in the face of changes to window size and display settings, you use the WPF layout system. Because most applications allow users to interact with data, you use data binding to reduce the work of integrating your UI with data. To enhance the visual appearance of your application, you use the comprehensive range of graphics, animation, and media support provided by WPF. Finally, if your application operates over text and documents, you can use the WPF text, typography, document, annotation, packaging, and printing capabilities.</p>
<p>Often, though, the basics are not enough for creating and managing a truly distinct and visually stunning user experience. The standard WPF controls may not integrate with the desired appearance of your application. Data may not be displayed in the most effective way. Your application&#8217;s overall user experience may not be suited to the default look and feel of Windows themes. In many ways, a presentation technology needs visual extensibility as much as any other kind of extensibility.</p>
<p>For this reason, WPF provides a variety of mechanisms for creating unique user experiences, including a rich content model for controls, triggers, control and data templates, styles, UI resources, and themes and skins.</p>
<h3 class="subHeading">Content Model</h3>
<div class="subsection">
<p>The main purpose of a majority of the WPF controls is to display content. In WPF, the type and number of items that can constitute the content of a control is referred to as the control&#8217;s <span class="parameter">content model</span>. Some controls can contain a single item and type of content; for example, the content of a <span>TextBox</span> is a string value that is assigned to the <span>Text</span> property. The following example sets the content of a <span>TextBox</span>.</p>
<div id="snippetGroup15">
<div id="ctl00_rs1_mainContentContainer_ctl557_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl557XAML');"><img class="LibC_copy_off" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" border="0" alt="" height="9" align="middle" /></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;Window
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
    x:Class=<span style="color:maroon;">"SDKSample.TextBoxContentWindow"</span>
    Title=<span style="color:maroon;">"TextBox Content"</span>&gt;

...

&lt;TextBox Text=<span style="color:maroon;">"This is the content of a TextBox."</span> /&gt;

...

&lt;/Window&gt;</pre>
</div>
</div>
</div>
<p>The following figure shows the result.</p>
<p><!--src=[../art/WPFIntroFigure21.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure21%28en-us,VS.90%29.png" alt="A TextBox control that contains text" /></p>
<p>Other controls, however, can contain multiple items of different types of content; the content of a <span>Button</span>, specified by the <span>Content</span> property, can contain a variety of items including layout controls, text, images, and shapes. The following example shows a <span>Button</span> with content that includes a <span>DockPanel</span>, a <span>Label</span>, a <span>Border</span>, and a <span>MediaElement</span>.</p>
<div id="snippetGroup16">
<div id="ctl00_rs1_mainContentContainer_ctl566_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl566XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;Window
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
    x:Class=<span style="color:maroon;">"SDKSample.ButtonContentWindow"</span>
    Title=<span style="color:maroon;">"Button Content"</span>&gt;

...

&lt;Button Margin=<span style="color:maroon;">"20"</span>&gt;
  &lt;!-- Button Content --&gt;
  &lt;DockPanel Width=<span style="color:maroon;">"200"</span> Height=<span style="color:maroon;">"180"</span>&gt;
    &lt;Label DockPanel.Dock=<span style="color:maroon;">"Top"</span> HorizontalAlignment=<span style="color:maroon;">"Center"</span>&gt;Click <span style="color:blue;">Me</span>!&lt;/Label&gt;
    &lt;Border Background=<span style="color:maroon;">"Black"</span> BorderBrush=<span style="color:maroon;">"Yellow"</span> BorderThickness=<span style="color:maroon;">"2"</span>
      CornerRadius=<span style="color:maroon;">"2"</span> Margin=<span style="color:maroon;">"5"</span>&gt;
      &lt;MediaElement Source=<span style="color:maroon;">"media/wpf.wmv"</span> Stretch=<span style="color:maroon;">"Fill"</span> /&gt;
    &lt;/Border&gt;
  &lt;/DockPanel&gt;
&lt;/Button&gt;

...

&lt;/Window&gt;</pre>
</div>
</div>
</div>
<p>The following figure shows the content of this button.</p>
<p><!--src=[../art/WPFIntroFigure22.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure22%28en-us,VS.90%29.png" alt="A button that contains multiple types of content" /></div>
<h3 class="subHeading">Triggers</h3>
<div class="subsection">
<p>Although the main purpose of XAML markup is to implement an application&#8217;s appearance, you can also use XAML to implement some aspects of an application&#8217;s behavior. One example is the use of triggers to change an application&#8217;s appearance based on user interactions.</p></div>
<h3 class="subHeading">Control Templates</h3>
<div class="subsection">
<p>The default UIs for WPF controls are typically constructed from other controls and shapes. For example, a <span>Button</span> is composed of both <span>ButtonChrome</span> and <span>ContentPresenter</span> controls. The <span>ButtonChrome</span> provides the standard button appearance, while the <span>ContentPresenter</span> displays the button&#8217;s content, as specified by the <span>Content</span> property.</p>
<p>Sometimes the default appearance of a control may be incongruent with the overall appearance of an application. In this case, you can use a <span>ControlTemplate</span> to change the appearance of the control&#8217;s UI without changing its content and behavior.</p>
<div id="snippetGroup17">
<div id="ctl00_rs1_mainContentContainer_ctl579_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl579XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;Window
  xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
  xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
  x:Class=<span style="color:maroon;">"SDKSample.ControlTemplateButtonWindow"</span>
  Title=<span style="color:maroon;">"Button with Control Template"</span> Height=<span style="color:maroon;">"158"</span> Width=<span style="color:maroon;">"290"</span>&gt;

  &lt;!-- Button using an ellipse --&gt;
  &lt;Button Content=<span style="color:maroon;">"Click Me!"</span> Click=<span style="color:maroon;">"button_Click"</span>&gt;
    &lt;Button.Template&gt;
      &lt;ControlTemplate TargetType=<span style="color:maroon;">"{x:Type Button}"</span>&gt;
        &lt;Grid Margin=<span style="color:maroon;">"5"</span>&gt;
          &lt;Ellipse Stroke=<span style="color:maroon;">"DarkBlue"</span> StrokeThickness=<span style="color:maroon;">"2"</span>&gt;
            &lt;Ellipse.Fill&gt;
              &lt;RadialGradientBrush Center=<span style="color:maroon;">"0.3,0.2"</span> RadiusX=<span style="color:maroon;">"0.5"</span> RadiusY=<span style="color:maroon;">"0.5"</span>&gt;
                &lt;GradientStop Color=<span style="color:maroon;">"Azure"</span> Offset=<span style="color:maroon;">"0.1"</span> /&gt;
                &lt;GradientStop Color=<span style="color:maroon;">"CornflowerBlue"</span> Offset=<span style="color:maroon;">"1.1"</span> /&gt;
              &lt;/RadialGradientBrush&gt;
            &lt;/Ellipse.Fill&gt;
          &lt;/Ellipse&gt;
          &lt;ContentPresenter Name=<span style="color:maroon;">"content"</span> HorizontalAlignment=<span style="color:maroon;">"Center"</span>
            VerticalAlignment=<span style="color:maroon;">"Center"</span>/&gt;
        &lt;/Grid&gt;
      &lt;/ControlTemplate&gt;
    &lt;/Button.Template&gt;

  &lt;/Button&gt;

&lt;/Window&gt;</pre>
</div>
</div>
</div>
<div id="snippetGroup18">
<div id="ctl00_rs1_mainContentContainer_ctl581_CSharp" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CodeDisplayLanguage">C#</div>
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl581CSharp');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;"><span style="color:blue;">using</span> System.Windows; // Window, RoutedEventArgs, MessageBox

<span style="color:blue;">namespace</span> SDKSample
{
    <span style="color:blue;">public</span> partial <span style="color:blue;">class</span> ControlTemplateButtonWindow : Window
    {
        <span style="color:blue;">public</span> ControlTemplateButtonWindow()
        {
            InitializeComponent();
        }

        <span style="color:blue;">void</span> button_Click(object sender, RoutedEventArgs e)
        {
            <span style="color:green;">// Show message box when button is clicked</span>
            MessageBox.Show(<span style="color:maroon;"><span style="color:maroon;">"Hello, Windows Presentation Foundation!"</span></span>);
        }
    }
}</pre>
</div>
</div>
</div>
<p>In this example, the default button UI has been replaced with an <span>Ellipse</span> that has a dark blue border and is filled using a <span>RadialGradientBrush</span>. The <span>ContentPresenter</span> control displays the content of the <span>Button</span>, &#8220;Click Me!&#8221; When the <span>Button</span> is clicked, the <span>Click</span> event is still raised as part of the <span>Button</span> control&#8217;s default behavior. The result is shown in the following figure.</p>
<p><!--src=[../art/WPFIntroFigure2.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure2%28en-us,VS.90%29.png" alt="An elliptical button and a second window" /></div>
<h3 class="subHeading">Data Templates</h3>
<div class="subsection">
<p>Whereas a control template lets you specify the appearance of a control, a data template lets you specify the appearance of a control&#8217;s content. Data templates are frequently used to enhance how bound data is displayed. The following figure shows the default appearance for a <span>ListBox</span> that is bound to a collection of <span class="code">Task</span> objects, where each task has a name, description, and priority.</p>
<p><!--src=[../art/WPFIntroFigure18.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure18%28en-us,VS.90%29.png" alt="A list box with the default appearance" /></p>
<p>The default appearance is what you would expect from a <span>ListBox</span>. However, the default appearance of each task contains only the task name. To show the task name, description, and priority, the default appearance of the <span>ListBox</span> control&#8217;s bound list items must be changed by using a <span>DataTemplate</span>. The following XAML defines such a <span>DataTemplate</span>, which is applied to each task by using the <span>ItemTemplate</span> attribute.</p>
<div id="snippetGroup19">
<div id="ctl00_rs1_mainContentContainer_ctl599_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl599XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;Window
  xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
  xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
  x:Class=<span style="color:maroon;">"SDKSample.DataTemplateWindow"</span>
  Title=<span style="color:maroon;">"With a Data Template"</span>&gt;

...

&lt;!-- Data Template (applied <span style="color:blue;">to</span> <span style="color:blue;">each</span> bound task item <span style="color:blue;">in</span> the task collection) --&gt;
&lt;DataTemplate x:Key=<span style="color:maroon;">"myTaskTemplate"</span>&gt;
  &lt;Border Name=<span style="color:maroon;">"border"</span> BorderBrush=<span style="color:maroon;">"DarkSlateBlue"</span> BorderThickness=<span style="color:maroon;">"2"</span>
    CornerRadius=<span style="color:maroon;">"2"</span> Padding=<span style="color:maroon;">"5"</span> Margin=<span style="color:maroon;">"5"</span>&gt;
    &lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
        &lt;RowDefinition/&gt;
        &lt;RowDefinition/&gt;
        &lt;RowDefinition/&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;Grid.ColumnDefinitions&gt;
        &lt;ColumnDefinition Width=<span style="color:maroon;">"Auto"</span> /&gt;
        &lt;ColumnDefinition /&gt;
      &lt;/Grid.ColumnDefinitions&gt;
      &lt;TextBlock Grid.Row=<span style="color:maroon;">"0"</span> Grid.Column=<span style="color:maroon;">"0"</span> Padding=<span style="color:maroon;">"0,0,5,0"</span> Text=<span style="color:maroon;">"Task Name:"</span>/&gt;
      &lt;TextBlock Grid.Row=<span style="color:maroon;">"0"</span> Grid.Column=<span style="color:maroon;">"1"</span> Text=<span style="color:maroon;">"{Binding Path=TaskName}"</span>/&gt;
      &lt;TextBlock Grid.Row=<span style="color:maroon;">"1"</span> Grid.Column=<span style="color:maroon;">"0"</span> Padding=<span style="color:maroon;">"0,0,5,0"</span> Text=<span style="color:maroon;">"Description:"</span>/&gt;
      &lt;TextBlock Grid.Row=<span style="color:maroon;">"1"</span> Grid.Column=<span style="color:maroon;">"1"</span> Text=<span style="color:maroon;">"{Binding Path=Description}"</span>/&gt;
      &lt;TextBlock Grid.Row=<span style="color:maroon;">"2"</span> Grid.Column=<span style="color:maroon;">"0"</span> Padding=<span style="color:maroon;">"0,0,5,0"</span> Text=<span style="color:maroon;">"Priority:"</span>/&gt;
      &lt;TextBlock Grid.Row=<span style="color:maroon;">"2"</span> Grid.Column=<span style="color:maroon;">"1"</span> Text=<span style="color:maroon;">"{Binding Path=Priority}"</span>/&gt;
    &lt;/Grid&gt;
  &lt;/Border&gt;
&lt;/DataTemplate&gt;

...

&lt;!-- Data template <span style="color:blue;">is</span> specified by the ItemTemplate attribute --&gt;
&lt;ListBox
  ItemsSource=<span style="color:maroon;">"{Binding}"</span>
  ItemTemplate=<span style="color:maroon;">"{StaticResource myTaskTemplate}"</span>
  HorizontalContentAlignment=<span style="color:maroon;">"Stretch"</span>
  IsSynchronizedWithCurrentItem=<span style="color:maroon;">"True"</span>
  Margin=<span style="color:maroon;">"5,0,5,5"</span> /&gt;

...

&lt;/Window&gt;</pre>
</div>
</div>
</div>
<p>The following figure shows the effect of this code.</p>
<p><!--src=[../art/WPFIntroFigure19.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure19%28en-us,VS.90%29.png" alt="A list box that uses a data template" /></p>
<p>Note that the <span>ListBox</span> has retained its behavior and overall appearance; only the appearance of the content being displayed by the list box has changed.</div>
<h3 class="subHeading">Styles</h3>
<div class="subsection">
<p>Styles enable developers and designers to standardize on a particular appearance for their product. WPF provides a strong style model, the foundation of which is the <span>Style</span> element. The following example creates a style that sets the background color for every <span>Button</span> on a window to <span class="code">Orange</span>.</p>
<div id="snippetGroup20">
<div id="ctl00_rs1_mainContentContainer_ctl606_XAML" class="libCScode">
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;Window
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
    x:Class=<span style="color:maroon;">"SDKSample.StyleWindow"</span>
    Title=<span style="color:maroon;">"Styles"</span>&gt;

...

&lt;!-- Style that will be applied <span style="color:blue;">to</span> all buttons --&gt;
&lt;Style TargetType=<span style="color:maroon;">"{x:Type Button}"</span>&gt;
  &lt;Setter <span style="color:blue;">Property</span>=<span style="color:maroon;">"Background"</span> Value=<span style="color:maroon;">"Orange"</span> /&gt;
  &lt;Setter <span style="color:blue;">Property</span>=<span style="color:maroon;">"BorderBrush"</span> Value=<span style="color:maroon;">"Crimson"</span> /&gt;
  &lt;Setter <span style="color:blue;">Property</span>=<span style="color:maroon;">"FontSize"</span> Value=<span style="color:maroon;">"20"</span> /&gt;
  &lt;Setter <span style="color:blue;">Property</span>=<span style="color:maroon;">"FontWeight"</span> Value=<span style="color:maroon;">"Bold"</span> /&gt;
  &lt;Setter <span style="color:blue;">Property</span>=<span style="color:maroon;">"Margin"</span> Value=<span style="color:maroon;">"5"</span> /&gt;
&lt;/Style&gt;

...

&lt;!-- This button will have the style applied <span style="color:blue;">to</span> it --&gt;
&lt;Button&gt;Click <span style="color:blue;">Me</span>!&lt;/Button&gt;

&lt;!-- This labe will <span style="color:blue;">not</span> have the style applied <span style="color:blue;">to</span> it --&gt;
&lt;Label&gt;Don<span style="color:green;">'t Click Me!&lt;/Label&gt;</span>

&lt;!-- This button will have the style applied <span style="color:blue;">to</span> it --&gt;
&lt;Button&gt;Click <span style="color:blue;">Me</span>!&lt;/Button&gt;

...

&lt;/Window&gt;</pre>
</div>
</div>
</div>
<p>Because this style targets all <span>Button</span> controls, the style is automatically applied to all the buttons in the window, as shown in the following figure.</p>
<p><!--src=[../art/WPFIntroFigure20.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure20%28en-us,VS.90%29.png" alt="Two orange buttons" /></div>
<h3 class="subHeading">Resources</h3>
<div class="subsection">
<p>Controls in an application should share the same appearance, which can include anything from fonts and background colors to control templates, data templates, and styles. You can use WPF&#8217;s support for user interface (UI) resources to encapsulate these resources in a single location for reuse.</p>
<p>The following example defines a common background color that is shared by a <span>Button</span> and a <span>Label</span>.</p>
<div id="snippetGroup21">
<div id="ctl00_rs1_mainContentContainer_ctl613_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl613XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;Window
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
    x:Class=<span style="color:maroon;">"SDKSample.ResourcesWindow"</span>
    Title=<span style="color:maroon;">"Resources Window"</span>&gt;

  &lt;!-- Define window-scoped background color resource --&gt;
  &lt;Window.Resources&gt;
    &lt;SolidColorBrush x:Key=<span style="color:maroon;">"defaultBackground"</span> Color=<span style="color:maroon;">"Red"</span> /&gt;
  &lt;/Window.Resources&gt;

...

&lt;!-- Button background <span style="color:blue;">is</span> defined by window-scoped resource --&gt;
&lt;Button Background=<span style="color:maroon;">"{StaticResource defaultBackground}"</span>&gt;One Button&lt;/Button&gt;

&lt;!-- Label background <span style="color:blue;">is</span> defined by window-scoped resource --&gt;
&lt;Label Background=<span style="color:maroon;">"{StaticResource defaultBackground}"</span>&gt;One Label&lt;/Label&gt;

...

&lt;/Window&gt;</pre>
</div>
</div>
</div>
<p>This example implements a background color resource by using the <span><span class="input">Window.Resources</span></span> property element. This resource is available to all children of the <span>Window</span>. There are a variety of resource scopes, including the following, listed in the order in which they are resolved:</p>
<ol>
<li>An individual control (using the inherited <span>FrameworkElement<span class="cs">.</span><span class="vb">.</span><span class="cpp">::</span><span class="nu">.</span>Resources</span> property).</li>
<li>A <span>Window</span> or a <span>Page</span> (also using the inherited <span>FrameworkElement<span class="cs">.</span><span class="vb">.</span><span class="cpp">::</span><span class="nu">.</span>Resources</span> property).</li>
<li>An <span>Application</span> (using the <span>Application<span class="cs">.</span><span class="vb">.</span><span class="cpp">::</span><span class="nu">.</span>Resources</span> property).</li>
</ol>
<p>The variety of scopes gives you flexibility with respect to the way in which you define and share your resources.</p>
<p>As an alternative to directly associating your resources with a particular scope, you can package one or more resources by using a separate <span>ResourceDictionary</span> that can be referenced in other parts of an application. For example, the following example defines a default background color in a resource dictionary.</p>
<div id="snippetGroup22">
<div id="ctl00_rs1_mainContentContainer_ctl625_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl625XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;ResourceDictionary
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>&gt;

  &lt;!-- Define background color resource --&gt;
  &lt;SolidColorBrush x:Key=<span style="color:maroon;">"defaultBackground"</span> Color=<span style="color:maroon;">"Red"</span> /&gt;

  &lt;!-- Define other resources --&gt;

...

&lt;/ResourceDictionary&gt;</pre>
</div>
</div>
</div>
<p>The following example references the resource dictionary defined in the previous example so that it is shared across an application.</p>
<div id="snippetGroup23">
<div id="ctl00_rs1_mainContentContainer_ctl626_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl626XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;Application
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
    x:Class=<span style="color:maroon;">"SDKSample.App"</span>&gt;

  &lt;Application.Resources&gt;
    &lt;ResourceDictionary&gt;
      &lt;ResourceDictionary.MergedDictionaries&gt;
        &lt;ResourceDictionary Source=<span style="color:maroon;">"BackgroundColorResources.xaml"</span>/&gt;
      &lt;/ResourceDictionary.MergedDictionaries&gt;
    &lt;/ResourceDictionary&gt;
  &lt;/Application.Resources&gt;

...

&lt;/Application&gt;</pre>
</div>
</div>
</div>
<p>Resources and resource dictionaries are the foundation of WPF support for themes and skins.</p></div>
<h3 class="subHeading">Themes and Skins</h3>
<div class="subsection">
<p>From a visual perspective, a theme defines the global appearance of Windows and the applications that run within it. Windows comes with several themes. For example, Microsoft Windows XP comes with both the Windows XP and Windows Classic themes, while Windows Vista comes with the Windows Vista and Windows Classic themes. The appearance that is defined by a theme defines the default appearance for a WPF application. WPF, however, does not integrate directly with Windows themes. Because the appearance of WPF is defined by templates, WPF includes one template for each of the well-known Windows themes, including Aero (Windows Vista), Classic (Microsoft Windows 2000), Luna (Microsoft Windows XP), and Royale (Microsoft Windows XP Media Center Edition 2005). These themes are packaged as resource dictionaries that are resolved if resources are not found in an application. Many applications rely on these themes to define their visual appearance; remaining consistent with Windows appearance helps users become familiar with more applications more easily.</p>
<p>On the other hand, the user experience for some applications does not necessarily come from the standard themes. For example, Microsoft Windows Media Player operates over audio and video data and benefits from a different style of user experience. Such UIs tend to provide customized, application-specific themes. These are known as skins, and applications that are skinned often provide hooks by which users can customize various aspects of the skin. Microsoft Windows Media Player has several prefabricated skins as well as a host of third-party skins.</p>
<p>Both themes and skins in WPF are most easily defined using resource dictionaries. The following example shows sample skin definitions.</p>
<div id="snippetGroup24">
<div id="ctl00_rs1_mainContentContainer_ctl629_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl629XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;!-- Blue Skin --&gt;
&lt;ResourceDictionary
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
    xmlns:local=<span style="color:maroon;">"clr-namespace:SDKSample"</span>&gt;
  &lt;Style TargetType=<span style="color:maroon;">"{x:Type Button}"</span>&gt;
    &lt;Setter <span style="color:blue;">Property</span>=<span style="color:maroon;">"Background"</span> Value=<span style="color:maroon;">"Blue"</span> /&gt;
  &lt;/Style&gt;

...

&lt;!-- Blue Skin --&gt;
&lt;ResourceDictionary
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
    xmlns:local=<span style="color:maroon;">"clr-namespace:SDKSample"</span>&gt;
  &lt;Style TargetType=<span style="color:maroon;">"{x:Type Button}"</span>&gt;
    &lt;Setter <span style="color:blue;">Property</span>=<span style="color:maroon;">"Background"</span> Value=<span style="color:maroon;">"Blue"</span> /&gt;
  &lt;/Style&gt;

...

&lt;/ResourceDictionary&gt;

...

&lt;/ResourceDictionary&gt;</pre>
</div>
</div>
</div>
<div id="snippetGroup25">
<div id="ctl00_rs1_mainContentContainer_ctl630_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl630XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;!-- Yellow Skin --&gt;
&lt;ResourceDictionary
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
    xmlns:local=<span style="color:maroon;">"clr-namespace:SDKSample"</span>&gt;
  &lt;Style TargetType=<span style="color:maroon;">"{x:Type Button}"</span>&gt;
    &lt;Setter <span style="color:blue;">Property</span>=<span style="color:maroon;">"Background"</span> Value=<span style="color:maroon;">"Yellow"</span> /&gt;
  &lt;/Style&gt;

...

&lt;!-- Yellow Skin --&gt;
&lt;ResourceDictionary
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
    xmlns:local=<span style="color:maroon;">"clr-namespace:SDKSample"</span>&gt;
  &lt;Style TargetType=<span style="color:maroon;">"{x:Type Button}"</span>&gt;
    &lt;Setter <span style="color:blue;">Property</span>=<span style="color:maroon;">"Background"</span> Value=<span style="color:maroon;">"Yellow"</span> /&gt;
  &lt;/Style&gt;

...

&lt;/ResourceDictionary&gt;

...

&lt;/ResourceDictionary&gt;</pre>
</div>
</div>
</div>
</div>
<h3 class="subHeading">Custom Controls</h3>
<p>Although WPF provides a host of customization support, you may encounter situations where existing WPF controls do not meet the needs of either your application or its users. This can occur when:</p>
<ul>
<li>The UI that you require cannot be created by customizing the look and feel of existing WPF implementations.</li>
<li>The behavior that you require is not supported (or not easily supported) by existing WPF implementations.</li>
</ul>
<p>At this point, however, you can take advantage of one of three WPF models to create a new control. Each model targets a specific scenario and requires your custom control to derive from a particular WPF base class. The three models are listed here:</p>
<ul>
<li><span class="label">User Control Model</span>. A custom control derives from <span>UserControl</span> and is composed of one or more other controls.</li>
<li><span class="label">Control Model</span>. A custom control derives from <span>Control</span> and is used to build implementations that separate their behavior from their appearance using templates, much like the majority of WPF controls. Deriving from <span>Control</span> allows you more freedom for creating a custom UI than user controls, but it may require more effort.</li>
<li><span class="label">Framework Element Model</span>. A custom control derives from <span>FrameworkElement</span> when its appearance is defined by custom rendering logic (not templates).</li>
</ul>
<p>The following example shows a custom numeric up/down control that derives from <span>UserControl</span>.</p>
<div id="snippetGroup26">
<div id="ctl00_rs1_mainContentContainer_ctl638_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl638XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;UserControl
  xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
  xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
  x:Class=<span style="color:maroon;">"SDKSample.NumericUpDown"</span>&gt;

  &lt;Grid&gt;

    &lt;Grid.RowDefinitions&gt;
      &lt;RowDefinition/&gt;
      &lt;RowDefinition/&gt;
    &lt;/Grid.RowDefinitions&gt;
    &lt;Grid.ColumnDefinitions&gt;
      &lt;ColumnDefinition/&gt;
      &lt;ColumnDefinition/&gt;
    &lt;/Grid.ColumnDefinitions&gt;

    &lt;!-- Value text box --&gt;
    &lt;Border BorderThickness=<span style="color:maroon;">"1"</span> BorderBrush=<span style="color:maroon;">"Gray"</span> Margin=<span style="color:maroon;">"2"</span> Grid.RowSpan=<span style="color:maroon;">"2"</span>
      VerticalAlignment=<span style="color:maroon;">"Center"</span> HorizontalAlignment=<span style="color:maroon;">"Stretch"</span>&gt;
      &lt;TextBlock Name=<span style="color:maroon;">"valueText"</span> Width=<span style="color:maroon;">"60"</span> TextAlignment=<span style="color:maroon;">"Right"</span> Padding=<span style="color:maroon;">"5"</span>/&gt;
    &lt;/Border&gt;

    &lt;!-- Up/Down buttons --&gt;
    &lt;RepeatButton Name=<span style="color:maroon;">"upButton"</span> Click=<span style="color:maroon;">"upButton_Click"</span> Grid.Column=<span style="color:maroon;">"1"</span>
      Grid.Row=<span style="color:maroon;">"0"</span>&gt;Up&lt;/RepeatButton&gt;
    &lt;RepeatButton Name=<span style="color:maroon;">"downButton"</span> Click=<span style="color:maroon;">"downButton_Click"</span> Grid.Column=<span style="color:maroon;">"1"</span>
      Grid.Row=<span style="color:maroon;">"1"</span>&gt;Down&lt;/RepeatButton&gt;

  &lt;/Grid&gt;

&lt;/UserControl&gt;</pre>
</div>
</div>
</div>
<div id="snippetGroup27">
<div id="ctl00_rs1_mainContentContainer_ctl640_CSharp" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CodeDisplayLanguage">C#</div>
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl640CSharp');"><br />
</a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;"><span style="color:blue;">using</span> System; // EventArgs
<span style="color:blue;">using</span> System.Windows; // DependencyObject, DependencyPropertyChangedEventArgs,
                      <span style="color:green;">// FrameworkPropertyMetadata, PropertyChangedCallback, </span>
                      <span style="color:green;">// RoutedPropertyChangedEventArgs</span>
<span style="color:blue;">using</span> System.Windows.Controls; // UserControl

<span style="color:blue;">namespace</span> SDKSample
{
    <span style="color:blue;">public</span> partial <span style="color:blue;">class</span> NumericUpDown : UserControl
    {
        <span style="color:green;">// NumericUpDown user control implementation</span>

...

    }
}</pre>
</div>
</div>
</div>
<p>The next example illustrates the XAML that is required to incorporate the user control into a <span>Window</span>.</p>
<div id="snippetGroup28">
<div id="ctl00_rs1_mainContentContainer_ctl642_XAML" class="libCScode">
<div class="CodeSnippetTitleBar">
<div class="CopyCodeButton"><a class="copyCode" title="Copy Code" href="CopyCode('ctl00_rs1_mainContentContainer_ctl642XAML');"></a></div>
</div>
<div dir="ltr">
<pre class="libCScode" style="white-space:pre-wrap;">&lt;Window
    xmlns=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span>
    xmlns:x=<span style="color:maroon;">"http://schemas.microsoft.com/winfx/2006/xaml"</span>
    x:Class=<span style="color:maroon;">"SDKSample.UserControlWindow"</span>
    xmlns:local=<span style="color:maroon;">"clr-namespace:SDKSample"</span>
    Title=<span style="color:maroon;">"User Control Window"</span>&gt;

...

&lt;!-- Numeric Up/Down user control --&gt;
&lt;local:NumericUpDown /&gt;

...

&lt;/Window&gt;</pre>
</div>
</div>
</div>
<p>The following figure shows the <span class="code">NumericUpDown</span> control hosted in a <span>Window</span>.</p>
<p><!--src=[../art/WPFIntroFigure3.png]--><img src="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure3%28en-us,VS.90%29.png" alt="A custom UserControl" /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/malleshv.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/malleshv.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/malleshv.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/malleshv.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/malleshv.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/malleshv.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/malleshv.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/malleshv.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/malleshv.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/malleshv.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/malleshv.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/malleshv.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/malleshv.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/malleshv.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=malleshv.wordpress.com&amp;blog=7188786&amp;post=28&amp;subd=malleshv&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://malleshv.wordpress.com/2009/04/02/wpf-windows-presentation-foundation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e7643e7e288f6580f0387f37fe6598a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">malleshv</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure24%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">Contoso Healthcare UI sample</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure10%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">A window that contains a button</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure25%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">A MessageBox</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure26%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">A main window and a dialog box</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure27%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">Two pages of a hosted application</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure11%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">DockPanel page</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Aa970268.DataBindingMostBasic%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">Basic data binding diagram</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure4%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">Ellipses and rectangles</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure12%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">A window with the text </media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure5%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">Various uses of a Path</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure6%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">Illustration of different brushes</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure13%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">Visual3D sample screen shot</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure7%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">Images of an animated cube</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure8%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">Thumbnail images and a full-size image</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure1%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">A MediaElement control with audio and video</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure23%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">Text with various text decorations</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure17%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">A FlowDocument within a FlowDocumentReader control</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure15%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">An XPS document within a DocumentViewer control</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure16%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">Annotation styling</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Global/Images/clear.gif" medium="image" />

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure21%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">A TextBox control that contains text</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure22%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">A button that contains multiple types of content</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure2%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">An elliptical button and a second window</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure18%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">A list box with the default appearance</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure19%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">A list box that uses a data template</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure20%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">Two orange buttons</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Aa970268.WPFIntroFigure3%28en-us,VS.90%29.png" medium="image">
			<media:title type="html">A custom UserControl</media:title>
		</media:content>
	</item>
		<item>
		<title>Understanding LINQ (C#)</title>
		<link>http://malleshv.wordpress.com/2009/04/02/understanding-linq-c/</link>
		<comments>http://malleshv.wordpress.com/2009/04/02/understanding-linq-c/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 07:36:33 +0000</pubDate>
		<dc:creator>malleshv</dc:creator>
				<category><![CDATA[.net]]></category>

		<guid isPermaLink="false">http://malleshv.wordpress.com/?p=23</guid>
		<description><![CDATA[Introduction New Language Features Automatic Properties Local Variable Type Inference Object Initializers &#38; Collection Initializers Anonymous Types Lambda Expressions Extension Methods Query Syntax Final Notes References &#38; Resources Introduction This article is about LINQ which I think is one of the most exciting features in Orcas. LINQ makes the concept of querying a first-class programming [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=malleshv.wordpress.com&amp;blog=7188786&amp;post=23&amp;subd=malleshv&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.codeproject.com/KB/linq/UnderstandingLINQ/UnderstandingLINQ1.png" border="0" alt="Figure 1" hspace="0" width="432" height="113" /></p>
<p><img src="http://www.codeproject.com/KB/linq/UnderstandingLINQ/UnderstandingLINQ2.png" border="0" alt="Figure 2" hspace="0" width="515" height="179" /></p>
<ul>
<li>Introduction</li>
<li>New Language Features
<ul>
<li>Automatic Properties</li>
<li>Local Variable Type Inference</li>
<li>Object Initializers &amp; Collection Initializers</li>
<li>Anonymous Types</li>
<li>Lambda Expressions</li>
<li>Extension Methods</li>
<li>Query Syntax</li>
</ul>
</li>
<li>Final Notes</li>
<li>References &amp; Resources</li>
</ul>
<p><strong>Introduction</strong></p>
<p>This article is about LINQ which I think is one of the most exciting features in Orcas. LINQ makes the concept of querying a first-class programming concept in .NET. The data to be queried can take the form of XML (LINQ to XML), databases (LINQ-enabled ADO.NET: LINQ to SQL, LINQ to Dataset and LINQ to Entities) and objects (LINQ to Objects). LINQ is also highly extensible and allows you to build custom LINQ enabled data providers (e.g.: LINQ to Amazon, LINQ to NHibernate, LINQ to LDAP).</p>
<p><img src="http://www.codeproject.com/KB/linq/UnderstandingLINQ/UnderstandingLINQ.gif" border="0" alt="LINQ Architecture (MSDN Magazine - June 2007)" hspace="0" width="541" height="382" /></p>
<p>I will discuss some of the new language features and improvements that are introduced in C# 3.0, and it is those features that enable the full power of LINQ which makes it possible to write something like this:</p>
<div id="premain0" class="SmallText" style="width:100%;cursor:pointer;"><span style="margin-bottom:0;"><br />
</span></div>
<pre style="margin-top:0;">var result = from c <span class="code-keyword">in</span> Customers
             where c.City == Boston<span class="code-string">"</span><span class="code-string">
             orderby c.LastName descending
             select new { c.FirstName, c.LastName, c.Address };</span></pre>
<p>Remember that if you want to play around with LINQ or try the examples yourself, you will need to download <a href="http://msdn2.microsoft.com/en-us/vstudio/aa700831.aspx">Visual Studio Orcas Beta 1</a>.<br />
In case you don&#8217;t want to download Visual Studio, you can check the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=1e902c21-340c-4d13-9f04-70eb5e3dceea">LINQ Preview (May 2006 CTP)</a> which runs on top of Visual Studio 2005 (there are a few changes in Beta 1 from the way LINQ worked in the May CTP).</p>
<p><strong>New Language Features</strong><a name="NewLanguageFeatures"><br />
</a></p>
<h3><a name="AutomaticProperties0">I. Automatic Properties<br />
</a></h3>
<div id="premain1" class="SmallText" style="width:100%;cursor:pointer;"><span style="margin-bottom:0;"><br />
</span></div>
<pre style="margin-top:0;"><span class="code-keyword">public</span> <span class="code-keyword">class</span> Point {
    <span class="code-keyword">private</span> <span class="code-keyword">int</span> _x, _y;
    <span class="code-keyword">public</span> <span class="code-keyword">int</span> X {
        <span class="code-keyword">get</span> { <span class="code-keyword">return</span> _x; }
        <span class="code-keyword">set</span> { _x = value; }
    }
    <span class="code-keyword">public</span> <span class="code-keyword">int</span> Y {
        <span class="code-keyword">get</span> { <span class="code-keyword">return</span> _y; }
        <span class="code-keyword">set</span> { _y = value; }
    }
}</pre>
<p>The above code simply defining a class with basic properties. Now with the new C# compiler in Orcas, we can write a shorter cleaner version using Automatic Properties which automatically generates the <code><span class="code-keyword">private</span></code> fields with <code>get</code>/<code>set </code>operations :</p>
<div id="premain2" class="SmallText" style="width:100%;cursor:pointer;"><span style="margin-bottom:0;"><br />
</span></div>
<pre style="margin-top:0;"><span class="code-keyword">public</span> <span class="code-keyword">class</span> Point {
    <span class="code-keyword">public</span> <span class="code-keyword">int</span> X { <span class="code-keyword">get</span>; <span class="code-keyword">set</span>; }
    <span class="code-keyword">public</span> <span class="code-keyword">int</span> Y { <span class="code-keyword">get</span>; <span class="code-keyword">set</span>; }
}</pre>
<p>The code above is even more readable and less verbose.<br />
Note that this feature has nothing to do with LINQ. I just thought it would be appropriate to list it with the other new language features.</p>
<h3><a name="LocalVariableTypeInference1">II. Local Variable Type Inference</a></h3>
<p>With this feature, the type of the local variable being declared is inferred from the expression used to initialize the variable. This is achieved using the <code>var</code> keyword (familiar to those who work with scripting languages, but actually it is quite different). It allows us to write the following code:</p>
<div id="premain3" class="SmallText" style="width:100%;cursor:pointer;"><span style="margin-bottom:0;"><br />
</span></div>
<pre style="margin-top:0;">var num = <span class="code-digit">50</span>;
var str = <span class="code-string">"</span><span class="code-string">simple string"</span>;
var obj = <span class="code-keyword">new</span> myType();
var numbers = <span class="code-keyword">new</span> <span class="code-keyword">int</span>[] {<span class="code-digit">1</span>,<span class="code-digit">2</span>,<span class="code-digit">3</span>};
var dic = <span class="code-keyword">new</span> Dictionary&lt;int,myType&gt;();</pre>
<p>The compiler would generate the same IL as if we compiled:</p>
<div id="premain4" class="SmallText" style="width:100%;cursor:pointer;"><span style="margin-bottom:0;"><br />
</span></div>
<pre style="margin-top:0;"><span class="code-keyword">int</span> num = <span class="code-digit">50</span>;
<span class="code-keyword">string</span> str = <span class="code-string">"</span><span class="code-string">simple string"</span>;
myType obj = <span class="code-keyword">new</span> myType();
<span class="code-keyword">int</span>[] numbers = <span class="code-keyword">new</span> <span class="code-keyword">int</span>[] {<span class="code-digit">1</span>,<span class="code-digit">2</span>,<span class="code-digit">3</span>};
Dictionary&lt;int,myType&gt; dic = <span class="code-keyword">new</span> Dictionary&lt;int,myType&gt;();</pre>
<p>Note that there is no un-typed variable reference nor late-binding happening, instead the compiler is inferring and declaring the type of the variable from the right-hand side of the assignment. As a result, the <code>var</code> keyword is generating a strongly typed variable reference.</p>
<h3><a name="ObjectInitializers2">III. Object Initializers &amp; Collection Initializers</a></h3>
<p>Let&#8217;s use the same <code>Point</code> class defined earlier, and suppose we want to define an instance of this class. We will have to create the object and start setting its properties, the code would look like this:</p>
<div id="premain5" class="SmallText" style="width:100%;cursor:pointer;"><span style="margin-bottom:0;"><br />
</span></div>
<pre style="margin-top:0;">Point p = <span class="code-keyword">new</span> Point();
p.X = <span class="code-digit">0</span>;
p.Y = <span class="code-digit">0</span>;</pre>
<p>This could be rewritten using Objects Initializers and combined into:</p>
<div id="premain6" class="SmallText" style="width:100%;cursor:pointer;"><span style="margin-bottom:0;"><br />
</span></div>
<pre style="margin-top:0;">Point p = <span class="code-keyword">new</span> Point() { X = <span class="code-digit">0</span>, Y = <span class="code-digit">0</span> };</pre>
<p>This feature can also be used with collection. Take a look at this example:</p>
<div id="premain7" class="SmallText" style="width:100%;cursor:pointer;"><span style="margin-bottom:0;"><br />
</span></div>
<pre style="margin-top:0;">List&lt;Point&gt; points = <span class="code-keyword">new</span> List&lt;Point&gt; {
    <span class="code-keyword">new</span> Point { X = <span class="code-digit">2</span>,  Y = <span class="code-digit">5</span> },
    <span class="code-keyword">new</span> Point { X = <span class="code-digit">1</span>, Y = -10 },
    <span class="code-keyword">new</span> Point { X = <span class="code-digit">3</span>, Y = <span class="code-digit">0</span> }
};</pre>
<p>Note that the compiler will generate a long hand code equivalent to the above one. It makes calls to the <code>Add()</code> method to add elements to the collection one at a time.</p>
<h3><a name="AnonymousTypes3">IV. Anonymous Types</a></h3>
<p>This language feature enable us to define inline types without having to explicitly define a class declaration for this type. In other words, imagine we want to use a <code>Point</code> object without defining the class <code>Point</code> (it would be anonymous). We will use the same object initializer syntax discussed earlier, but without the type name:</p>
<div id="premain8" class="SmallText" style="width:100%;cursor:pointer;"><span style="margin-bottom:0;"><br />
</span></div>
<pre style="margin-top:0;">var p = <span class="code-keyword">new</span> {X = <span class="code-digit">0</span>, Y = <span class="code-digit">2</span>};</pre>
<p>Inside Orcas, you will have full intellisense support. So when you use the variable <code>p</code> you will get a list of properties that this anonymous type has.</p>
<h3><a name="LambdaExpressions4">V. Lambda Expressions</a></h3>
<p>C# 2.0 introduced anonymous methods, which allow code blocks to be written &#8220;in-line&#8221; where delegate values are expected. While anonymous methods provide the power of functional programming languages, the syntax is rather verbose. Lambda expressions provide a more concise, functional syntax for writing anonymous methods. A lambda expression is written as a parameter list (can be implicitly typed), followed by the <code>=<span class="code-keyword">&gt;</span></code> token, followed by an expression or a statement block.</p>
<p>As an example, let&#8217;s define a <code><span class="code-keyword">delegate</span></code> type <code>MyDeleg</code> as:</p>
<div id="premain9" class="SmallText" style="width:100%;cursor:pointer;"><span style="margin-bottom:0;"><br />
</span></div>
<pre style="margin-top:0;"><span class="code-keyword">delegate</span> R MyDeleg&lt;A,R&gt;(A arg);</pre>
<p>We can then write using anonymous methods:</p>
<div id="premain10" class="SmallText" style="width:100%;cursor:pointer;"><span style="margin-bottom:0;"><br />
</span></div>
<pre style="margin-top:0;">MyDeleg&lt;int,bool&gt; IsPositive = <span class="code-keyword">delegate</span>(<span class="code-keyword">int</span> num) {
                                   <span class="code-keyword">return</span> num &gt; <span class="code-digit">0</span>;
                               };</pre>
<p>Or we can use the new lambda expressions to write:</p>
<div id="premain11" class="SmallText" style="width:100%;cursor:pointer;"><span style="margin-bottom:0;"><br />
</span></div>
<pre style="margin-top:0;">MyDeleg&lt;int,bool&gt; IsPositive = num =&gt; num &gt; <span class="code-digit">0</span>;</pre>
<h3><a name="ExtensionMethods5">VI. Extension Methods</a></h3>
<p>Extension methods make it possible to extend existing types and constructed types with additional methods, without having to derive from them or recompile the original type. So instead of writing helper methods for objects, they become part of that object itself.</p>
<p>As an example, suppose we want to check a <code><span class="code-SDKkeyword">string</span></code> to see if it is a valid email address. We would do this by writing a function that takes a <code><span class="code-SDKkeyword">string</span></code> as an argument and returns a <code><span class="code-keyword">true</span></code>/<code><span class="code-keyword">false</span></code>. With Extension Methods, we can do the following:</p>
<div id="premain12" class="SmallText" style="width:100%;cursor:pointer;"><span style="margin-bottom:0;"><br />
</span></div>
<pre style="margin-top:0;"><span class="code-keyword">public</span> <span class="code-keyword">static</span> <span class="code-keyword">class</span> MyExtensions {
    <span class="code-keyword">public</span> <span class="code-keyword">static</span> <span class="code-keyword">bool</span> IsValidEmailAddress(<span class="code-keyword">this</span> <span class="code-keyword">string</span> s) {
        Regex regex = <span class="code-keyword">new</span> Regex( <span class="code-string">@"</span><span class="code-string">^[w-.]+@([w-]+.)+[w-]{2,4}$"</span> );
        <span class="code-keyword">return</span> regex.IsMatch(s);
    }
}</pre>
<p>We defined a <code><span class="code-keyword">static</span></code> class with a <code><span class="code-keyword">static</span> </code>method containing the Extension Method. Note how the <code><span class="code-keyword">static</span> </code>method above has a <code><span class="code-keyword">this</span></code> keyword before the first parameter argument of type <code><span class="code-SDKkeyword">string</span></code>. This tells the compiler that this particular Extension Method should be added to objects of type <code><span class="code-SDKkeyword">string</span></code>. And then we can call it from the <code><span class="code-SDKkeyword">string</span> </code>as a member function:</p>
<div id="premain13" class="SmallText" style="width:100%;cursor:pointer;"><span style="margin-bottom:0;"><br />
</span></div>
<pre style="margin-top:0;"><span class="code-keyword">using</span> MyExtensions;

<span class="code-keyword">string</span> email = Request.QueryString[<span class="code-string">"</span><span class="code-string">email"</span>];
<span class="code-keyword">if</span> ( email.IsValidEmailAddress() ) {
    <span class="code-comment">//</span><span class="code-comment"> ...</span>
}</pre>
<p>It is worth mentioning that LINQ syntax makes use of built-in Extension Methods (e.g. <code>where()</code>, <code>orderby()</code>, <code>select()</code>, <code>sum()</code>, <code>average()</code> and many more) that reside in the new <code>System.Linq <span class="code-keyword">namespace</span></code> in Orcas and define standard query operators that can be used against relational databases, XML and any .NET objects that implement <code>IEnumerable<span class="code-keyword">&lt;</span>T<span class="code-keyword">&gt;</span></code>.</p>
<h3><a name="QuerySyntax6">VII. Query Syntax</a></h3>
<p>Query expressions provide a language integrated syntax for queries that is similar to relational and hierarchical query languages such as SQL and XQuery. It is a shorthand for writing queries using the LINQ query operators (i.e. <code>from...where...select</code>). Visual Studio provides full intellisense and compile-time checking support for query syntax.<br />
When the C# compiler encounters a query syntax expression, it actually transforms it into explicit method invocation code that uses Extension Methods and Lambda Expressions.</p>
<p>To explain this, let me give an example:</p>
<div id="premain14" class="SmallText" style="width:100%;cursor:pointer;"></div>
<pre style="margin-top:0;">var result = from c <span class="code-keyword">in</span> Customers
             where c.City.StartsWith(<span class="code-string">"</span><span class="code-string">B"</span>)
             orderby c.LastName
             select <span class="code-keyword">new</span> { c.FirstName, c.LastName, c.Address };</pre>
<p>The above code is equivalent to the following:</p>
<div id="premain15" class="SmallText" style="width:100%;cursor:pointer;"></div>
<pre style="margin-top:0;">var result = Customers.Where( c =&gt; c.City.StartsWith(<span class="code-string">"</span><span class="code-string">B"</span>) )
                      .OrderBy( c =&gt; c.LastName  )
                      .Select( c =&gt; <span class="code-keyword">new</span> { c.FirstName, c.LastName, c.Address } );</pre>
<p>The advantage of using Query Syntax is that the code is easier and more readable.<br />
Also note that a query expression begins with a <code>from</code> clause and ends with either a <code>select</code> or <code>group</code> clause.</p>
<p><strong>Final Notes</strong><a name="FinalNotes"><br />
</a></p>
<p>Most of the language features introduced in C# v3.0 that we saw (such as variable type inference, object initializers, anonymous types and lambda expressions) are only &#8220;compiler tricks&#8221;/&#8221;syntactic sugar&#8221; which means that the IL the compiler generates is the same as the long code version, therefore they are independent from the framework (NetFX) and runtime (CLR). However, they do need some framework support and specifically the &#8220;green bits&#8221; (.NET Framework v3.5) <em>System.Core.dll</em> assembly. This is why extension methods, which in fact work at compile time (syntactic sugar), still rely on <code>System.Runtime.CompilerServices.ExtensionAttribute</code> introduced in <em>System.Core.dll</em>.<br />
On the other hand, query expressions syntax is just a mapping to the extension methods implementations that resides in <code>System.Linq</code>, <code>System.Data.Linq</code> and <code>System.Xml.Linq <span class="code-keyword">namespace</span></code>s.</p>
<p><strong>References and Resources</strong><a name="Resources"><br />
</a></p>
<ul>
<li><a href="http://weblogs.asp.net/scottgu/archive/2007/05/15/new-orcas-language-feature-anonymous-types.aspx">&#8220;New Orcas Language Feature&#8221; Series by Scott Guthrie</a>: Great series explaining LINQ</li>
<li><a href="http://www.danielmoth.com/Blog/2007/02/linq-resources.html">LINQ Resources</a>: Blog entries by Daniel Moth</li>
<li><a href="http://msdn.microsoft.com/msdnmag/issues/07/06/CSharp30/">MSDN Magazine (June 2007)</a>: An article on C# 3.0 and LINQ</li>
<li><a href="http://msdn2.microsoft.com/en-us/bb330936.aspx">Visual Studio Orcas Samples</a>: C#/VB LINQ Samples for Beta 1</li>
<li><a href="http://msdn2.microsoft.com/en-us/vcsharp/aa336745.aspx">Future Versions</a>: C# 3.0</li>
<li><a href="http://msdn2.microsoft.com/en-us/netframework/aa904594.aspx">The LINQ Project</a>: Home of the LINQ Project</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/malleshv.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/malleshv.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/malleshv.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/malleshv.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/malleshv.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/malleshv.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/malleshv.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/malleshv.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/malleshv.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/malleshv.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/malleshv.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/malleshv.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/malleshv.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/malleshv.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=malleshv.wordpress.com&amp;blog=7188786&amp;post=23&amp;subd=malleshv&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://malleshv.wordpress.com/2009/04/02/understanding-linq-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e7643e7e288f6580f0387f37fe6598a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">malleshv</media:title>
		</media:content>

		<media:content url="http://www.codeproject.com/KB/linq/UnderstandingLINQ/UnderstandingLINQ1.png" medium="image">
			<media:title type="html">Figure 1</media:title>
		</media:content>

		<media:content url="http://www.codeproject.com/KB/linq/UnderstandingLINQ/UnderstandingLINQ2.png" medium="image">
			<media:title type="html">Figure 2</media:title>
		</media:content>

		<media:content url="http://www.codeproject.com/KB/linq/UnderstandingLINQ/UnderstandingLINQ.gif" medium="image">
			<media:title type="html">LINQ Architecture (MSDN Magazine - June 2007)</media:title>
		</media:content>
	</item>
		<item>
		<title>Sending SMS using GSM Modem in c#</title>
		<link>http://malleshv.wordpress.com/2009/04/01/sending-sms-using-gsm-modem-in-c/</link>
		<comments>http://malleshv.wordpress.com/2009/04/01/sending-sms-using-gsm-modem-in-c/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 07:42:22 +0000</pubDate>
		<dc:creator>malleshv</dc:creator>
				<category><![CDATA[SMS + GSM Modem]]></category>

		<guid isPermaLink="false">http://malleshv.wordpress.com/?p=9</guid>
		<description><![CDATA[When do you want to send SMS via applications? There could be plethora of use cases for this. The simplest one is to validate a mobile number, and some of the complicated ones could involve sending an SMS after a huge workflow is complete or gone wrong. Let&#8217;s find out ways to send SMS using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=malleshv.wordpress.com&amp;blog=7188786&amp;post=9&amp;subd=malleshv&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When do you want to send SMS via applications? There could be plethora of use cases for this. The simplest one is to validate a mobile number, and some of the complicated ones could involve sending an SMS after a huge workflow is complete or gone wrong. Let&#8217;s find out ways to send SMS using C#/VB.NET.</p>
<p><strong>Sending SMS</strong></p>
<p>What are the ways in which one can send SMS?</p>
<ul>
<li>Using a GSM modem:
<ul>
<li>Better when one wants to implement offline applications and a very small number of SMS go every minute, usually few 10s.</li>
</ul>
</li>
<li>Using web service:
<ul>
<li>Better when it is an online application and a very few number of SMS go every minute, usually few 10s.</li>
</ul>
</li>
<li>Using endpoints given by service the provider:
<ul>
<li>Better when the number of SMS exceeds a few 100s per minute. Service provider demands a commitment of at least 100,000 SMS per month.</li>
</ul>
</li>
</ul>
<p>Sending SMS via a webservice or endpoints is simplest. In contrast, sending SMS via GSM modem has a few additional steps to take care of. Let&#8217;s understand each in detail.</p>
<p><strong>Sending SMS using GSM Modem</strong></p>
<ol>
<li>First, find the best GSM modem that suits the needs.</li>
<li>Understand the AT Command set<a title="Sample AT command set that works with most GSM Modems" href="http://www.gsm-modem.de/gsm-faq.html"> </a>required to communicate with the modem.</li>
<li>Connect the modem to the computer according to the setup guide specified in the manual provided with the GSM modem.  The connection settings explained are common for most GSM modems.</li>
<li>Create a new Windows application or Web Application.</li>
<li>Add a new class file with the name SMSCOMMS.</li>
<li>Copy and paste the code given below into the class.</li>
</ol>
<p><strong>Code</strong></p>
<pre style="margin-top:0;display:block;"><span class="code-keyword">using</span> System;
<span class="code-keyword">using</span> System.Threading;
<span class="code-keyword">using</span> System.ComponentModel;
<span class="code-keyword">using</span> System.IO.Ports;   

<span class="code-keyword">public</span> <span class="code-keyword">class</span> SMSCOMMS
{
    <span class="code-keyword">private</span> SerialPort SMSPort;
    <span class="code-keyword">private</span> Thread SMSThread;
    <span class="code-keyword">private</span> Thread ReadThread;
    <span class="code-keyword">public</span> <span class="code-keyword">static</span> <span class="code-keyword">bool</span> _Continue = <span class="code-keyword">false</span>;
    <span class="code-keyword">public</span> <span class="code-keyword">static</span> <span class="code-keyword">bool</span> _ContSMS = <span class="code-keyword">false</span>;
    <span class="code-keyword">private</span> <span class="code-keyword">bool</span> _Wait = <span class="code-keyword">false</span>;
    <span class="code-keyword">public</span> <span class="code-keyword">static</span> <span class="code-keyword">bool</span> _ReadPort = <span class="code-keyword">false</span>;
    <span class="code-keyword">public</span> <span class="code-keyword">delegate</span> <span class="code-keyword">void</span> SendingEventHandler(<span class="code-keyword">bool</span> Done);
    <span class="code-keyword">public</span> <span class="code-keyword">event</span> SendingEventHandler Sending;
    <span class="code-keyword">public</span> <span class="code-keyword">delegate</span> <span class="code-keyword">void</span> DataReceivedEventHandler(<span class="code-keyword">string</span> Message);
    <span class="code-keyword">public</span> <span class="code-keyword">event</span> DataReceivedEventHandler DataReceived;    

    <span class="code-keyword">public</span> SMSCOMMS(<span class="code-keyword">ref</span> <span class="code-keyword">string</span> COMMPORT)
    {
        SMSPort = <span class="code-keyword">new</span> SerialPort();
        SMSPort.PortName = COMMPORT;
        SMSPort.BaudRate = <span class="code-digit">9600</span>;
        SMSPort.Parity = Parity.None;
        SMSPort.DataBits = <span class="code-digit">8</span>;
        SMSPort.StopBits = StopBits.One;
        SMSPort.Handshake = Handshake.RequestToSend;
        SMSPort.DtrEnable = <span class="code-keyword">true</span>;
        SMSPort.RtsEnable = <span class="code-keyword">true</span>;
        SMSPort.NewLine = System.Environment.NewLine;
        ReadThread = <span class="code-keyword">new</span> Thread(
            <span class="code-keyword">new</span> System.Threading.ThreadStart(ReadPort));
    }    

    <span class="code-keyword">public</span> <span class="code-keyword">bool</span> SendSMS(<span class="code-keyword">string</span> CellNumber, <span class="code-keyword">string</span> SMSMessage)
    {
        <span class="code-keyword">string</span> MyMessage = <span class="code-keyword">null</span>;
        <span class="code-comment">//</span><span class="code-comment">Check if Message Length &lt;= 160
</span>
        <span class="code-keyword">if</span> (SMSMessage.Length &lt;= <span class="code-digit">160</span>)
            MyMessage = SMSMessage;
        <span class="code-keyword">else</span>
            MyMessage = SMSMessage.Substring(<span class="code-digit">0</span>, <span class="code-digit">160</span>);
        <span class="code-keyword">if</span> (IsOpen == <span class="code-keyword">true</span>)
        {
            SMSPort.WriteLine(<span class="code-string">"</span><span class="code-string">AT+CMGS="</span> + CellNumber + <span class="code-string">"</span><span class="code-string">r"</span>);
            _ContSMS = <span class="code-keyword">false</span>;
                SMSPort.WriteLine(
                MyMessage + System.Environment.NewLine + (<span class="code-keyword">char</span>)(<span class="code-digit">26</span>));
              _Continue = <span class="code-keyword">false</span>;
            <span class="code-keyword">if</span> (Sending != <span class="code-keyword">null</span>)
                Sending(<span class="code-keyword">false</span>);
        }
        <span class="code-keyword">return</span> <span class="code-keyword">false</span>;
    }    

    <span class="code-keyword">private</span> <span class="code-keyword">void</span> ReadPort()
    {
        <span class="code-keyword">string</span> SerialIn = <span class="code-keyword">null</span>;
        <span class="code-keyword">byte</span>[] RXBuffer = <span class="code-keyword">new</span> <span class="code-keyword">byte</span>[SMSPort.ReadBufferSize + <span class="code-digit">1</span>];
        <span class="code-keyword">string</span> SMSMessage = <span class="code-keyword">null</span>;
        <span class="code-keyword">int</span> Strpos = <span class="code-digit">0</span>;
        <span class="code-keyword">string</span> TmpStr = <span class="code-keyword">null</span>;
        <span class="code-keyword">while</span> (SMSPort.IsOpen == <span class="code-keyword">true</span>)
        {
            <span class="code-keyword">if</span> ((SMSPort.BytesToRead != <span class="code-digit">0</span>) &amp; (SMSPort.IsOpen == <span class="code-keyword">true</span>))
            {
                <span class="code-keyword">while</span> (SMSPort.BytesToRead != <span class="code-digit">0</span>)
                {
                    SMSPort.Read(RXBuffer, <span class="code-digit">0</span>, SMSPort.ReadBufferSize);
                    SerialIn =
                        SerialIn + System.Text.Encoding.ASCII.GetString(
                        RXBuffer);
                            <span class="code-keyword">if</span> (SerialIn.Contains(<span class="code-string">"</span><span class="code-string">&gt;"</span>) == <span class="code-keyword">true</span>)
                    {
                        _ContSMS = <span class="code-keyword">true</span>;
                    }
                    <span class="code-keyword">if</span> (SerialIn.Contains(<span class="code-string">"</span><span class="code-string">+CMGS:"</span>) == <span class="code-keyword">true</span>)
                    {
                        _Continue = <span class="code-keyword">true</span>;
                        <span class="code-keyword">if</span> (Sending != <span class="code-keyword">null</span>)
                            Sending(<span class="code-keyword">true</span>);
                        _Wait = <span class="code-keyword">false</span>;
                        SerialIn = <span class="code-keyword">string</span>.Empty;
                        RXBuffer = <span class="code-keyword">new</span> <span class="code-keyword">byte</span>[SMSPort.ReadBufferSize + <span class="code-digit">1</span>];
                    }
                }
                <span class="code-keyword">if</span> (DataReceived != <span class="code-keyword">null</span>)
                    DataReceived(SerialIn);
                SerialIn = <span class="code-keyword">string</span>.Empty;
                RXBuffer = <span class="code-keyword">new</span> <span class="code-keyword">byte</span>[SMSPort.ReadBufferSize + <span class="code-digit">1</span>];
            }
        }
    }    

    <span class="code-keyword">public</span> <span class="code-keyword">bool</span> SendSMS(<span class="code-keyword">string</span> CellNumber, <span class="code-keyword">string</span> SMSMessage)
    {
        <span class="code-keyword">string</span> MyMessage = <span class="code-keyword">null</span>;
        <span class="code-keyword">if</span> (SMSMessage.Length &lt;= <span class="code-digit">160</span>)
        {
            MyMessage = SMSMessage;
        }
        <span class="code-keyword">else</span>
        {
            MyMessage = SMSMessage.Substring(<span class="code-digit">0</span>, <span class="code-digit">160</span>);
        }
        <span class="code-keyword">if</span> (IsOpen == <span class="code-keyword">true</span>)
        {
            SMSPort.WriteLine(<span class="code-string">"</span><span class="code-string">AT+CMGS="</span> + CellNumber + <span class="code-string">"</span><span class="code-string">r"</span>);
            _ContSMS = <span class="code-keyword">false</span>;
                SMSPort.WriteLine(
                    MyMessage + System.Environment.NewLine + (<span class="code-keyword">char</span>)(<span class="code-digit">26</span>));
              _Continue = <span class="code-keyword">false</span>;
            <span class="code-keyword">if</span> (Sending != <span class="code-keyword">null</span>)
                Sending(<span class="code-keyword">false</span>);
        }
        <span class="code-keyword">return</span> <span class="code-keyword">false</span>;
    }    

    <span class="code-keyword">public</span> <span class="code-keyword">void</span> Open()
    {
        <span class="code-keyword">if</span> (IsOpen == <span class="code-keyword">false</span>)
        {
            SMSPort.Open();
                ReadThread.Start();
        }
    }    

    <span class="code-keyword">public</span> <span class="code-keyword">void</span> Close()
    {
        <span class="code-keyword">if</span> (IsOpen == <span class="code-keyword">true</span>)
        {
            SMSPort.Close();
        }
    }    

}
 Then use the Code as:

SMSEngine = <span class="code-keyword">new</span> SMSCOMMS(<span class="code-string">"</span><span class="code-string">COM1"</span>);
SMSEngine.Open();
SMSEngine.SendSMS(<span class="code-string">"</span><span class="code-string">919888888888"</span>,<span class="code-string">"</span><span class="code-string">THIS IS YOUR MESSAGE"</span>);
SMSEngine.Close()</pre>
<p><strong>Other Ways</strong></p>
<p><strong>Via Web Services</strong></p>
<p>Sending SMS via webservices, although not for real-time services, is a very cost-effective solution. There are lots of webservices and you should be able to find one by searching the web. There are free ones that are not so reliable. So, purchase SMS credits to send a limited number of SMS using a webservice. Here, the usage is very simple, as it is just consuming a webservice to send a number and message to a function.</p>
<p><strong>via Service end-points</strong></p>
<p>Sending SMS via service provider is also similar to using a webservice. Here, it may be a non-standard protocol or over HTTP. It differs from service provider to service provider. Some provide sample code that can be used for programming custom applications.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/malleshv.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/malleshv.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/malleshv.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/malleshv.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/malleshv.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/malleshv.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/malleshv.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/malleshv.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/malleshv.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/malleshv.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/malleshv.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/malleshv.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/malleshv.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/malleshv.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=malleshv.wordpress.com&amp;blog=7188786&amp;post=9&amp;subd=malleshv&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://malleshv.wordpress.com/2009/04/01/sending-sms-using-gsm-modem-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e7643e7e288f6580f0387f37fe6598a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">malleshv</media:title>
		</media:content>
	</item>
	</channel>
</rss>
