Tuesday, 19 February 2013

Properties in Silverlight


Properties in Silverlight

Hi friends,

In this article i am explaingin properties in silverlight.

There are two ways to reference properties in XAML: in line with the element as
you would any XML attribute and as a nested subelement. Which you should
choose depends on what you need to represent. Simple values are typically represented
with inline properties, whereas complex values are typically represented with
element properties.


1. INLINE PROPERTIES

The use of an inline property requires a type converter that will convert the string representation—
for example, the "Black" in Background="Black"—into a correct
underlying .NET type (in this case, a SolidColorBrush).

Ex
<Grid x:Name="LayoutRoot" Background="Black" />



2.ELEMENT PROPERTIES

Another way to specify properties is to use the expanded property element syntax.
While this can generally be used for any property, it’s typically required only when you
need to specify something more complex than the inline syntax will easily allow. The
syntax for element properties is <Type.PropertyName>value</Type.PropertyName>,


<Grid x:Name="LayoutRoot">
<Grid.Background>
Black
</Grid.Background>
</Grid>


3.Dependency properties

Storing a dependency property differs in that the location
of its backing value depends upon its current state. The way that location is determined
is called value precedence.
VALUE PRECEDENCE
Dependency properties obtain their value from a variety of inputs. What follows is the
order the Silverlight property system uses when assigning the runtime values of
dependency properties, with the highest precedence listed first:


4 .Attached properties
Attached properties are a specialized type of dependency property that is immediately
recognizable in markup due to the TypeName.AttachedPropertyName syntax. For example,
Canvas.Left is an attached property defined by the Canvas type. What makes
attached properties interesting is that they’re not defined by the type you use them
with; instead, they’re defined by another type in a potentially different class hierarchy.


PROPERTY PATHS
Before we wrap up our discussion of properties, there’s one concept left to understand:
property paths. Property paths provide a way to reference properties of objects in
XAML both when you have a name for an element and when you need to indirectly
refer to an element by its position in the tree



Happy Programming!!
Don’t forget to leave your feedback and comments below!
If you have any query mail me to Sujeet.bhujbal@gmail.com     
Regards
Sujeet Bhujbal
--------------------------------------------------------------------------------
-----------------------------------------------------------------------------------

0 comments :

Post a Comment