Подтвердить что ты не робот

Silverlight 4 RelativeSource FindAncestor binding

Будет ли RelativeSource FindAncestor, AncestorType... в Silverlight 4?

4b9b3361

Ответ 1

В Silverlight 4 свойство RelativeSource Binding по-прежнему поддерживает только "Self" и "TemplatedParent", в Silverlight 3 нет изменений в этой области.

Ответ 2

RelativeSource AncestorType поддерживается в Silverlight 5, который доступен сейчас.

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

Ответ 3

Возможно, вы могли бы создать экземпляр ViewModel в XMAL в качестве статического ресурса, а затем ссылаться на него как на источник в вашей привязке.

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