Silverlight 4 RelativeSource привязка FindAncestor [закрыто]
будет ли RelativeSource FindAncestor, AncestorType... в Silverlight 4?
4 ответов
в Silverlight 4 RelativeSource
собственность Binding
по-прежнему поддерживает только "Self" и "TemplatedParent", в этой области нет изменений от Silverlight 3.
RelativeSource AncestorType
поддерживается в Silverlight 5, который доступен сейчас.
<TextBlock Text="{Binding Name}"
FontSize="{Binding DataContext.CustomFontSize,
RelativeSource={RelativeSource AncestorType=UserControl}}"
/>
возможно, вы могли бы создать экземпляр ViewModel в XMAL как статический ресурс, а затем ссылаться на него как на источник в привязке.
<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>