.net Silverlight 4相对资源FindAncestor绑定
是否会有相对的资源查找或取消存储类型。。。在Silverlight 4中?在Silverlight 4中,.net Silverlight 4相对资源FindAncestor绑定,.net,silverlight,binding,relativesource,.net,Silverlight,Binding,Relativesource,是否会有相对的资源查找或取消存储类型。。。在Silverlight 4中?在Silverlight 4中,绑定的相对资源属性仍然只支持“Self”和“TemplatedParent”,与Silverlight 3在这方面没有变化。这可能有助于: 也许您可以在XMAL中将ViewModel实例化为一个静态资源,然后在绑定中将其作为源引用 <UserControl.Resources> <vm:MainPageViewModel x:Key="ViewModel"/>
绑定的相对资源
属性仍然只支持“Self”和“TemplatedParent”,与Silverlight 3在这方面没有变化。这可能有助于:
也许您可以在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>
相对资源存储类型
,现在可用
<TextBlock Text="{Binding Name}"
FontSize="{Binding DataContext.CustomFontSize,
RelativeSource={RelativeSource AncestorType=UserControl}}"
/>