2010-02-18 13 views

cevap

27

Binding ait RelativeSource özelliği hala sadece bu alanda Silverlight 3 hiçbir değişiklik olduğunda, "Self" ve "TemplatedParent" destekler.

4

Belki Xmal içinde ViewModel örneğini verebilir senin bağlayıcı içinde kaynak olarak. artık kullanılabilir

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

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