SIGN UP MEMBER LOGIN:    
ARTICLE

XAML Property values in Silverlight/WPF

Posted by Sanket Terdal Articles | Silverlight with C# July 19, 2010
In this article, I am going demo various ways we can set property values in XAML using Silverlight.
Reader Level:

HTML clipboard

Introduction:

In this article, I am going demo various ways we can set property values in XAML using Silverlight. XAML provides several different ways to set property values:

  1. Simple Properties
  2. Type Converters
  3. Complex Properties
  4. Markup Extensions
  5. Attached Properties

We will see all above properties in detail.

1. Simple Properties: These are properties that provide values as simple strings. For example Content and Name property of button control.

     XAML1.gif

2. Type Converters: These properties that Markup supplies as strings. For example

  • Height and Width property of button. Internally it is converted to integer.
  • HorizontalAlignment and VerticalAlignment property of a button. Internally it is converted from string to number that corresponds to enumerated value Bottom, Top, Center, and Stretch.

    XAML2.gif
3. Complex Properties: These are the properties whose values are not as simple as strings but are represented as nested elements.

    XAML3.gif

4. Markup Extensions: These are the properties whose values are set dynamically at runtime. The property can be set declaratively.
  • Property = {Binding ElementName=ObjectName, Path=PropertyName}

  • XAML4.gif
5. Attached Properties: Attached property is a type of global property that is settable on any object. The purpose of an attached property is to allow different child elements to specify unique values for a property that is actually defined in a parent element.
The type that defines the attached property typically follows one of these models:
  • The type that defines the attached property is designed so that it can be the parent element of the elements that will set values for the attached property. The type then iterates its child objects through internal logic against some object tree structure, obtains the values, and acts on those values in some manner.

  •  
  • The type that defines the attached property represents a service. Other types set values for the attached property. Then, when the element that set the property is evaluated in the context of the service, the attached property values are obtained through internal logic of the service class.

    Here in following example Grid is of 2 rows and 2 columns and button is placed in each cell.

    XAML5.gif
Conclusion: In this article, we have seen the various ways value of property that can be set in Silverlight or WPF.
 

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
Become a Sponsor