使用超链接从子控件更改父导航框架

时间:2010-07-02 16:33:17

标签: silverlight hyperlink navigation

我想我可能在措辞方面遇到了问题(对于silverlight及其控件不熟悉),但总体目标和问题是:

我用“MainPage.xaml”创建了一个silverlight应用程序。在页面内是一个网格,它有两个基本控件:导航:框架[我们可以像微软在他们的演示中一样调用这个ContentFrame]和我创建的另一个控件,包括页面顶部的横幅和简单的导航[用于这个解决方案可以称之为BannerControl]

BannerControl在该点内有链接(或应该指向)项目中的各个页面。他们点击横幅中的链接,然后MainPage应该填充ContentFrame(或者我希望如此)。情况似乎并非如此。

我的第一个想法是控件如何关联,BannerControl是一个孩子,而不是看到NavigationFrame。也许这是我对这一切应该如何工作的无法解释,这会给我带来问题,但无论哪种方式,我都处在路障中。

有人可以指导我如何获得工作链接吗?

MainPage.xaml中:

<Grid x:Name="LayoutRoot" Style="{StaticResource LayoutRootStyle}">
    <Grid x:Name="ContentRoot" Style="{StaticResource ContentRootStyle}">
        <StackPanel>
            <local:NavigationBar/>
            <navigation:Frame x:Name="ContentFrame" Source="/Pages" Navigated="ContentFrame_Navigated" NavigationFailed="ContentFrame_NavigationFailed" Margin="25,5">
                <navigation:Frame.UriMapper>
                    <uriMapper:UriMapper>
                        <uriMapper:UriMapping Uri="" MappedUri="/Pages/Welcome.xaml"/>
                        <uriMapper:UriMapping Uri="/IT/{pageName}" MappedUri="/pages/IT/{pageName}.xaml"/>
                        <uriMapper:UriMapping Uri="/RM/{pageName}" MappedUri="/pages/IT/{pageName}.xaml"/>
                        <uriMapper:UriMapping Uri="/RSG/{pageName}" MappedUri="/pages/IT/{pageName}.xaml"/>
                        <uriMapper:UriMapping Uri="/RSM/{pageName}" MappedUri="/pages/IT/{pageName}.xaml"/>
                        <uriMapper:UriMapping Uri="/{pageName}" MappedUri="/pages/{pageName}.xaml"/>
                    </uriMapper:UriMapper>
                </navigation:Frame.UriMapper>
            </navigation:Frame>
        </StackPanel>
    </Grid>
</Grid>

横幅内的链接:

<StackPanel x:Name="NavBarSubNavRSG" Style="{StaticResource NavBarSubNavStyle}" 
            Visibility="Collapsed">
    <Rectangle Style="{StaticResource NavBarSubNavPadStyle}"/>
    <HyperlinkButton x:Name="NavBarSubRSGOneLink" Content="RSG One" 
                     Style="{StaticResource NavBarSubNavLinkStyle}"/>
    <Rectangle Style="{StaticResource NavBarSubNavRectStyle}"/>
    <HyperlinkButton x:Name="NavBarSubRSGTwoLink" Content="RSG Two" 
                     Style="{StaticResource NavBarSubNavLinkStyle}"/>
    <Rectangle Style="{StaticResource NavBarSubNavRectStyle}"/>
    <HyperlinkButton x:Name="NavBarSubRSGThreeLink" Content="RSG Three" 
                     Style="{StaticResource NavBarSubNavLinkStyle}"/>
    <Rectangle Style="{StaticResource NavBarSubNavRectStyle}"/>
    <HyperlinkButton x:Name="NavBarSubRSGFourLink" Content="RSG Four" 
                     Style="{StaticResource NavBarSubNavLinkStyle}"/>
</StackPanel>

1 个答案:

答案 0 :(得分:3)

您需要设置HyperlinkBut​​ton的NavigateUri和TargetName属性。 NavigateUri指向页面的Uri,TargetName是x:框架的名称:

<sdk:Frame 
   x:Name="ContentFrame"/> 

...

<HyperlinkButton 
    x:Name="NavBarSubRSGFourLink" 
    Content="RSG One" 
    NavigateUri="RSGOne.xaml" 
    Target="ContentFrame"/>
相关问题