Hierarchical navigation and pages in different files

Hello,

I’m trying to create an application with different kind of navigations, some parts will have a hierarchical and some other just direct navigation. I’m having trouble using both, but that is another question. Let’s say I have this:

<Panel>
    <HierarchicalNavigation ux:Name="nav" ReuseExistingNode="false" Active="mainPage" />

    <Style>
        <Page>
            <EnteringAnimation>
                <Move X="1" RelativeTo="ParentSize" />
            </EnteringAnimation>
            <ExitingAnimation>
                <Move X="-1" RelativeTo="ParentSize" />
            </ExitingAnimation>
        </Page>
    </Style>
    <ListPage />
    <DetailPage />
</Panel>

So ListPage and DetailPage are in separate files with something like this:like

<Page ux:Name="listPage" ux:Class="ListPage">
    <StackPanel>
        <Button Text="Page 1">
            <Clicked>
                <NavigateTo Target="detailPage" />
            </Clicked>
        </Button>
    </StackPanel>
</Page>

And DetailPage more or less the same, you can imagine. The thing is that NavigateTo doesn’t compile because: “‘detailPage’ declared at DetailPage.ux(1) is a member of the class ‘DetailPage’ and cannot be accessed from class ‘ListPage’.”

So is there any way of having this working while keeping file separated?. The code above is just a very simple example, the actual page code is much longer and if they have to be in the same file is going to be hell to edit them…

Thank you always and sorry for so many questions!

You can handle this with ux:Include which simply inserts the contents of the target File at the desired location. :slight_smile:

In your case you simply:

  • remove the ux:Class="ListPage" at the top of your ListPage.ux file. (since you want to include “a block of text” rather than creating a new class)
  • replace <ListPage/> inside MainView.ux with <ux:Include File="ListPage.ux"/> in order to insert the ux at that specific position.
  • Do the same for the DetailPage

Got it, great, I’ll try right now!!

Works, thanks!!

So my problem now is how to combine two different kind of navigations. Please allow me to explain, I have the following pages:

Top Page showing an artist list My page with some stuff Favorites with some stuff

All these pages have a bottombar with links to each others. Navigation between these should be direct, no animation / hierarchy needed.

But inside top page I do have two subpages: the list and the details I talked about in my first post (most likely they will be many more). These must have hierarchical navigation including also top page, this means if I click on top page artist, it goes to some listing about that artist, and from there to detail, and if going back twice then it goes all the way back to top page.

… I tried the following, but no succeed at all (please allow me to just use classes instead of ux:include for this example):

<Panel>
    <Direct Navigation Active="{view.mainPage}"/>
    <TopPage />
    <Panel>
        <HierarchicalNavigation Active="{view.ticketPage}" />
        <ListPage />
        <DetailPage />
    </Panel>
    <MyPage />
    <FavoritesPage />
</Panel>

TopPage should be included also in hierarchical navigation, but don’t know how to do it. Also this doesn’t work, I change navigation to ListPage but it is never shown…

Thank you once more !!

Oh, I did some quick schema:

I’ve done something like this in this example: https://www.fusetools.com/community/forums/show_and_tell/kind_of_generic_page_creation_and_navigation_based

It uses direct navigation only, but based on settings it can be done in a way, that it is hierarchical.

Oskar: This does something similar to what you describe, I guess?

The one “trick” here is that the direct navigation which is conceptually the top level is here actually housed inside the first page of the hierarchical navigation instead. I.e. that first page uses direct navigation to let you select between 3 menus which serve up different options for where to go with hierarchical navigation afterwards. :slight_smile:

<App Theme="Basic">

    <!-- Used for direct nav. Hides inactive pages -->
    <Page ux:Class="dirPage" ux:Name="self">
        <WhileActive Invert="true">
            <Change self.Visibility="Hidden"/>
        </WhileActive>
    </Page>

    <!-- Animations for hierarchical nav -->
    <DockPanel ux:Class="subpage">
        <EnteringAnimation>
            <Move X="1" RelativeTo="Size"/>
        </EnteringAnimation>
        <ExitingAnimation>
            <Move X="-1" RelativeTo="Size"/>
        </ExitingAnimation>
    </DockPanel>

    <!-- Adds a back-button for the lower levels of hierarchical nav. -->
    <subpage ux:Class="subsubpage">
        <Button Text="Back" Dock="Top" Alignment="TopLeft">
            <Clicked>
                <GoBack/>
            </Clicked>
        </Button>
    </subpage>

    <ClientPanel>
        <Panel>
            <HierarchicalNavigation ux:Name="Hnav" Duration="0.3"/>

            <!-- First page for Hierarchical nav. This *contains* everything related to the direct navigation -->
            <subpage ux:Name="toplevel">
                <DockPanel>
                    <Panel>
                        <DirectNavigation ux:Name="Dnav" Active="topPage"/>

                        <dirPage ux:Name="topPage">
                            <StackPanel>
                                <Text>Top page</Text>
                                <Button Text="To 2nd level">
                                    <Clicked>
                                        <NavigateTo Target="p1_2" NavigationContext="Hnav"/>
                                    </Clicked>
                                </Button>
                            </StackPanel>
                        </dirPage>

                        <dirPage ux:Name="myPage" >
                            <Text>My page</Text>
                        </dirPage>

                        <dirPage ux:Name="favPage">
                            <StackPanel>
                                <Text>Favourites</Text>
                                <Button Text="To 2nd level">
                                    <Clicked>
                                        <NavigateTo Target="p3_2" NavigationContext="Hnav"/>
                                    </Clicked>
                                </Button>
                            </StackPanel>
                        </dirPage>
                    </Panel>

                    <Grid Dock="Bottom" ColumnCount="3">
                        <Button Text="1">
                            <Clicked>
                                <NavigateTo Target="topPage" NavigationContext="Dnav"/>
                            </Clicked>
                        </Button>
                        <Button Text="2">
                            <Clicked>
                                <NavigateTo Target="myPage" NavigationContext="Dnav"/>
                            </Clicked>
                        </Button>
                        <Button Text="3">
                            <Clicked>
                                <NavigateTo Target="favPage" NavigationContext="Dnav"/>
                            </Clicked>
                        </Button>
                    </Grid>
                </DockPanel>
            </subpage>

            <!-- the pages further down in the navigation hierarchy -->
            <subsubpage ux:Name="p1_2" ux:AutoBind="false">
                <StackPanel>
                    <Text>2nd level of Top Page</Text>
                    <Button Text="To 3rd level">
                        <Clicked>
                            <NavigateTo Target="p1_3" NavigationContext="Hnav"/>
                        </Clicked>
                    </Button>
                </StackPanel>
            </subsubpage>

            <subsubpage ux:Name="p1_3" ux:AutoBind="false">
                <Text>3rd level of Top Page</Text>
            </subsubpage>

            <subsubpage ux:Name="p3_2" ux:AutoBind="false">
                <Text>2nd level of Favourites</Text>
            </subsubpage>

        </Panel>
    </ClientPanel>
</App>

This is just great, thank you so much!!

I checked the code and it works great! thank you very much for it! I’m trying now to refactor the whole xml tree I have so I can do the navigation propertly, but I do have another question (sorry for so many, if you come to Tokyo one day, you have a sushi dinner paid, I promise!)

Using the above structure, I have now the two navigations:

<..>
<HierarchicalNavigation ux:Name="hNav" Duration="0.3" Active="{view.subPage}" />
<..>
 <DirectNavigation ux:Name="dNav" Active="{view.mainPage}" />

If I change the observable subPage, nothing happens with hierarchical navigation (direct navigation works right away)

So I guess NavigateTo and NavigationContext are very relevant, so I tried also the following in the buttons:

<Clicked>
   <NavigateTo Target="{view.subPage}" NavigationContext="hNav" />
</Clicked>

But still didn’t work. I’m doing this because I have everything split into a lot of files and the buttons are depth in the hierarchy so I was relying in JS Observable for navigation control instead of refactoring the whole markup.

Is there any way of doing this?

Once again, thank you so much !!

Unfortunately there is a bug with databinding the Active property of HierarchicalNavigation and I’m not sure when this will be fixed.

For the time being you’ll either have to use NavigateTo with “absolute” Targets (as in the code I pasted) or try to achieve a similar experience using some of the other navigation modes. (Switching between multiple linear navigations might achieve the same but is obviously clumsier and a bit more bloated).

We apologise for the inconvenience.

How can I use this example as follow?

<Match Value="{status}">
  <Case Number="200">
    <NavigateTo Target="p1_2" NavigationContext="Hnav"/>
  </Case>
  <Case Number="422">
    <Text Font="RobotoLight" Alignment="HorizontalCenter" Opacity=".5" Value="{msg}" />
  </Case>
</Match>

In general I believe the purpose of <Match> is to manage different layout sub-trees and not to trigger actions (such as NavigateTo).

However, since data binding the Active property for a HierarchicalNavigation doesn’t work it becomes hard to implement this in a clean way (= using JS logic for the navigation). So, we can do this little hack :slight_smile:

<Match Value="{status}">
    <Case Number="200">
        <Panel>
            <WhileTrue Value="true" Bypass="Never">
                <NavigateTo Target="p1_2" NavigationContext="Hnav"/>
            </WhileTrue>
        </Panel>
    </Case>
    <Case Number="422">
        <Text Font="RobotoLight" Alignment="HorizontalCenter" Opacity=".5" Value="{msg}" />
    </Case>
</Match>

Set up this way the WhileTrue will autotrigger the NavigateTo-action as soon as that sub-tree becomes active. The surrounding Panel is just there because WhileTrue needs a node to attach to. It might not be terribly elegant but it does the job. :slight_smile:

@remi very kindly and cleverly solution! Thank you. :slight_smile: