会不会有RelativeSource FindAncestor,AncestorType...在Silverlight 4中?
发布于 2010-02-19 05:24:33
在Silverlight4中,Binding的RelativeSource属性仍然只支持"Self“和"TemplatedParent",这方面与Silverlight3没有什么不同。
发布于 2011-12-20 00:25:46
RelativeSource AncestorType is supported in Silverlight 5,现已推出。
<TextBlock Text="{Binding Name}"
FontSize="{Binding DataContext.CustomFontSize,
RelativeSource={RelativeSource AncestorType=UserControl}}"
/>发布于 2010-10-08 19:48:39
也许您可以将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>https://stackoverflow.com/questions/2291310
复制相似问题