Silverlight 4 RelativeSource FindAncestor binding [closed]

拥有回忆 提交于 2019-12-23 07:19:04

问题


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


回答1:


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




回答2:


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

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



回答3:


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:


This may help:

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



来源:https://stackoverflow.com/questions/2291310/silverlight-4-relativesource-findancestor-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!