As we have seen in the previous post XAML provides new generation of opportunities by which we can describe an object. Here we'll cover the remaining two concepts
- Attached Properties
- Markup Extensions
Going back to previous example of TextBlock which is shown below
<TextBlock Text="Title:" Style="{StaticResource TextBlockStyle}"
Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right"></TextBlock>
Attached Properties refers to the ability by which child objects can set properties of parent object. In this control Grid (parent control) contains this TextBlock (child control). The way it helps is child elements inform the parent element of how they are to be presented in the user interface (UI). Another possiblity is different child elements unique values for the same parent element depending their own suitability. A point not be missed here is that a control which sports Attached Properties should implement them as Dependency properties in it own definition.
Alright! Markup Extensions.
Basically it refers to the attribute value being picked up from a collection which is described elsewhere. In the above example the Collection of StaticResource(s) can be put inside App.xaml (which is common markup for all your applications in the assembly) like this
<Application.Resources>
<Style x:Key="TextBlockStyle" TargetType="TextBlock">
<Setter Property="ForeGround" Value="Black"></Setter>
<Setter Property="Margin" Value="2"></Setter>
</Style></Application.Resources>
Similar we can have a Binding Markup like
Text="{Binding QuantityOnHand}"
where QuantityOnHand is column in an IEnumerable collection.
No comments:
Post a Comment