Y aura-t-il RelativeSource FindAncestor, AncestorType ... dans Silverlight 4?Silverlight 4 Liaison RelativeSource FindAncestor
21
A
Répondre
27
Dans Silverlight 4, la propriété RelativeSource
de Binding
prend toujours uniquement en charge "Self" et "TemplatedParent", Silverlight 3 ne subit aucune modification dans cette zone.
3
4
Peut-être que vous pourriez instancier ViewModel dans le XMAL comme une ressource statique de référence alors que la source de votre liaison.
<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>
16
RelativeSource AncestorType
is supported in Silverlight 5, qui est maintenant disponible.
<TextBlock Text="{Binding Name}"
FontSize="{Binding DataContext.CustomFontSize,
RelativeSource={RelativeSource AncestorType=UserControl}}"
/>