2010-02-18 4 views

Antwort

27

In Silverlight 4 unterstützt die RelativeSource Eigenschaft von Binding immer noch nur "Self" und "TemplatedParent", es gibt keine Änderung von Silverlight 3 in diesem Bereich.

4

Vielleicht könnten Sie das Ansichtsmodell in den xMAL instanziiert als eine statische Ressource dann als Quelle verweisen, die in Ihrer Bindung.

<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> 
16

RelativeSource AncestorTypeis supported in Silverlight 5, die jetzt verfügbar ist.

<TextBlock Text="{Binding Name}" 
      FontSize="{Binding DataContext.CustomFontSize, 
       RelativeSource={RelativeSource AncestorType=UserControl}}" 
/>