2010-02-18 12 views

Odpowiedz

27

Właściwość Binding nadal obsługuje tylko "Self" i "TemplatedParent", nie ma żadnej zmiany z Silverlight 3 w tym obszarze.

4

Może ty instancji ViewModel w Xmal jako zasób statyczny następnie odwołać że jako źródło w twojej wiążące.

<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, który jest już dostępny.

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