2010-09-17 50 views
6

這一直困擾着我很長一段時間,我似乎無法找到一個很好的解釋。這個標記中的圓括號的目的是什麼?它是一個XAML快捷方式嗎?爲什麼它似乎只用於動畫?爲什麼需要圍繞XAML動畫的屬性值使用圓括號?

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

回答

4

這是用於指定Type合格DependencyProperty的語法。這是必需的,因爲Storyboard.TargetProperty附加屬性可以附加到任何DependencyObject。這意味着XAML解析器將不知道如何解析屬性,除非它們完全合格。

該語法還用於綁定到附加屬性等內容。這是一個人爲的例子來證明這一點:

<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> 

如果從Binding刪除括號,你會得到一個綁定錯誤(因爲沒有網格屬性Border元素)。

0

它不僅用於動畫(驗證彈簧到腦海) - 它們分別只是靜態調用或強制轉換。基本上在上述代碼轉換爲(在僞代碼):

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

其中元件是做出響應並newValue爲動畫設置屬性的元素。

相關問題