tags:

views:

17

answers:

2

This has been bugging me for a long time now and I can't seem to find a good explanation for it. What is the purpose of the brackets in this markup? Is it a XAML shortcut for casting? Why does it only seem to be used for animations?

Storyboard.TargetProperty="(TextBlock.RenderTransform).(RotateTransform.Angle)"

If anyone has an

A: 

It isn't only used for animations (Validation springs to mind) - they are simply static calls or casts, respectively. Basically the above code translates to (in pseudo-code):

((RotateTransform)TextBlock.GetRenderTransform((TextBlock) element)).Angle = newValue;

where element is the element that is acted upon and newValue is the animation setting properties.

Goblin
+2  A: 

This is syntax for specifying a Type qualified DependencyProperty. It is required, because the Storyboard.TargetProperty attached property can be attached to any DependencyObject. That means the XAML parser won't know how to resolve the properties unless they are fully qualified.

This syntax is also used for things like binding to attached properties. Here is a contrived example to demonstrate this:

<Grid>  
  <Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="*" />
  </Grid.RowDefinitions>
    <Border x:Name="Foo" Background="Blue" Grid.Row="10" />
    <Border x:Name="Bar" Background="Red" Height="{Binding (Grid.Row), ElementName=Foo}" />
</Grid>

If you remove the parenthesis from the Binding, you'll get a binding error (because there is no Grid property on the Border element).

Abe Heidebrecht