21

Silverlight 4 に RelativeSource FindAncestor、AncestorType... はありますか?

4

4 に答える 4

27

Silverlight 4では、のRelativeSourceプロパティはBinding「Self」と「TemplatedParent」のみをサポートします。この領域でのSilverlight3からの変更はありません。

于 2010-02-18T21:24:32.523 に答える
16

RelativeSource AncestorType 現在利用可能なSilverlight5でサポートされています。

<TextBlock Text="{Binding Name}" 
           FontSize="{Binding DataContext.CustomFontSize, 
               RelativeSource={RelativeSource AncestorType=UserControl}}"
/>
于 2011-12-19T16:25:45.877 に答える
4

おそらく、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>
于 2010-10-08T11:48:38.793 に答える
3

これは役立つかもしれません:

http://blog.thekieners.com/2010/09/08/relativesource-binding-with-findancestor-mode-in-silverlight/

于 2010-09-18T10:33:19.720 に答える