开发者

Change parent navigation frame from a child control with a hyperlink

I think I'm possibly having trouble wording it (being new to silverlight and its controls) but the general goal and problem is this:

I have created a silverlight application with "MainPage.xaml". Within the page is a grid that has two basic controls: a navigation:Frame [we can call this ContentFrame as Microsoft has done in their demos] and another control I have created consisting a top-of-page banner and simple navigation [for the sake of this solution this can be called the BannerControl]

The BannerControl has links within that point to (or should point to) various pages within my project. They click a link in the banner and the MainPage should then populate the ContentFrame (or so I would hope). This does not appear to be the case.

My first thought is just how the controls relate and the BannerControl being a child and not possibly seeing the NavigationFrame. Maybe it's my grossly-inept interpretation of how this should all work that's giving me issues, but either way I am at a road block.

Could someone give me guidance as to how I can get the links to 开发者_StackOverflow中文版work?

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>

Links within the Banner:

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


You need to set the NavigateUri and TargetName properties of your HyperlinkButton. NavigateUri points to the Uri of your page and TargetName is the x:Name of your Frame:

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

...

<HyperlinkButton 
    x:Name="NavBarSubRSGFourLink" 
    Content="RSG One" 
    NavigateUri="RSGOne.xaml" 
    Target="ContentFrame"/>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜