【发布时间】:2011-01-18 11:28:09
【问题描述】:
Silverlight 4 中会有RelativeSource FindAncestor、AncestorType...吗?
【问题讨论】:
标签: .net silverlight binding relativesource
Silverlight 4 中会有RelativeSource FindAncestor、AncestorType...吗?
【问题讨论】:
标签: .net silverlight binding relativesource
RelativeSource AncestorTypeis supported in Silverlight 5,现已上市。
<TextBlock Text="{Binding Name}"
FontSize="{Binding DataContext.CustomFontSize,
RelativeSource={RelativeSource AncestorType=UserControl}}"
/>
【讨论】:
也许您可以将 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>
【讨论】:
在 Silverlight 4 中,Binding 的 RelativeSource 属性仍然只支持“Self”和“TemplatedParent”,这方面与 Silverlight 3 没有任何变化。
【讨论】: