Developer's Academy: Understanding Default Properties in XAML

Tuesday, 2 September 2014

Understanding Default Properties in XAML

Since XAML is essentially an XML document, we can embed elements inside of other elements.

For Example:

<Page>
   <Grid ...>
      <Button ... />
      <TextBlock … />
   </Grid>
</Page>

Here Page "contains" a Grid and the Grid "contains" a Button and a TextBlock. Or, perhaps more correctly in XAML parlance, that Page’s Content property is set to Grid, and Grid's Children collection includes the Button and TextBlock. Depending on the type of control you're working with, the default property can be populated using this embedded style syntax. 

So, you could do this:

<TextBlock Content="Click Me" ... />

... or this ...

<Button HorizontalAlignment="Left"
        Margin="246,102,0,0"
        VerticalAlignment="Top"> Hi
</Button>


In simple words the default property of a XAML element is the property that we can simply put "between the tags" without any specific references.

No comments:

Post a Comment