开发者

Silverlight 4 RelativeSource FindAncestor binding [closed]

开发者 https://www.devze.com 2022-12-20 10:04 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_JS百科 Closed 10 years ago.

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


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


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

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


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>


This may help:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号