Silverlight 4 RelativeSource FindAncestor binding

2019-06-14 21:53发布

Will there be RelativeSource FindAncestor, AncestorType... in Silverlight 4?

4条回答
做自己的国王
3楼-- · 2019-06-14 22:25

Perhaps you could instantiate the ViewModel in the XMAL as a static resource then reference that as the source in your binding.

<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>
查看更多
戒情不戒烟
4楼-- · 2019-06-14 22:31

RelativeSource AncestorType is supported in Silverlight 5, which is available now.

<TextBlock Text="{Binding Name}" 
           FontSize="{Binding DataContext.CustomFontSize, 
               RelativeSource={RelativeSource AncestorType=UserControl}}"
/>
查看更多
看我几分像从前
5楼-- · 2019-06-14 22:36

In Silverlight 4 the RelativeSource property of Binding still only supports "Self" and "TemplatedParent", there is no change from Silverlight 3 in this area.

查看更多
登录 后发表回答