在Silverlight 4中是否会有RelativeSource FindAncestor、AncestorType等功能?
在Silverlight 4中是否会有RelativeSource FindAncestor、AncestorType等功能?
Binding
的 RelativeSource
属性仍然只支持 "Self" 和 "TemplatedParent",与 Silverlight 3 相比在这个领域没有改变。RelativeSource AncestorType
在现在已经可以使用了,它在Silverlight 5中得到了支持。
<TextBlock Text="{Binding Name}"
FontSize="{Binding DataContext.CustomFontSize,
RelativeSource={RelativeSource AncestorType=UserControl}}"
/>
<UserControl.Resources>
<vm:MainPageViewModel x:Key="ViewModel"/>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource ViewModel}}">
<ListBox ItemsSource="{Binding Partitions}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel FlowDirection="LeftToRight" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Button Margin="10,0" Width="40" Content="{Binding}" Command="{Binding Source={StaticResource ViewModel}, Path=ButtonCommand}" CommandParameter="{Binding}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>