Silverlight 4中是否会有RelativeSource FindAncestor,AncestorType?
答案 0 :(得分:27)
在Silverlight 4中,RelativeSource
的{{1}}属性仍然只支持“Self”和“TemplatedParent”,此区域的Silverlight 3没有变化。
答案 1 :(得分:16)
RelativeSource AncestorType
is supported in Silverlight 5,现已上市。
<TextBlock Text="{Binding Name}"
FontSize="{Binding DataContext.CustomFontSize,
RelativeSource={RelativeSource AncestorType=UserControl}}"
/>
答案 2 :(得分: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>
答案 3 :(得分:3)