Silverlight 4中会有RelativeSource FindAncestor, AncestorType...吗?
问问题
24279 次
4 回答
27
在 Silverlight 4 中,该RelativeSource
属性Binding
仍然只支持“Self”和“TemplatedParent”,这方面与 Silverlight 3 没有任何变化。
于 2010-02-18T21:24:32.523 回答
16
RelativeSource AncestorType
Silverlight 5 支持,现在可用。
<TextBlock Text="{Binding Name}"
FontSize="{Binding DataContext.CustomFontSize,
RelativeSource={RelativeSource AncestorType=UserControl}}"
/>
于 2011-12-19T16:25:45.877 回答
4
也许您可以将 XMAL 中的 ViewModel 实例化为静态资源,然后将其作为绑定中的源引用。
<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>
于 2010-10-08T11:48:38.793 回答
3
这可能会有所帮助:
http://blog.thekieners.com/2010/09/08/relativesource-binding-with-findancestor-mode-in-silverlight/
于 2010-09-18T10:33:19.720 回答