views:

98

answers:

1

I have an application that has a top level navigation menu which consists of series of buttons within a stackpanel. When a user clicks on a button the view model processes the command and updates the value of CurrentView (type UserControl). The CurrentView is bound to the element ContentControl as below.

<ContentControl Content="{Binding CurrentView}" />

I want the 'menu' to keep track of where the user is so that I can change the foreground of the navigation buttons, so users know where they are. What is the best way to do this? Should I wrap this 'menu' into a control?

Some of the views passed to the ContentControl will have their own sub menus. These submenus work in the same way, and I would like to change the foreground and background for these.

+1  A: 

Most of what you are talking about here is typically done by using a Frame, and Navigation with Pages of content. Is there a specific reason you are not using this?

For Example:

<sdk:Frame x:Name="CenterFrame" BorderThickness="0" Source="/Home">
<sdk:Frame.UriMapper>
    <sdk:UriMapper>
        <sdk:UriMapping Uri="/Job/{ID}" MappedUri="/Views/JobView.xaml?ID={ID}"/>
        <sdk:UriMapping Uri="/Home" MappedUri="/Views/HomeView.xaml"/>
        <sdk:UriMapping Uri="/Resource/{ResourceName}" MappedUri="/Views/ResourceView.xaml?Resource={ResourceName}"/>
        <sdk:UriMapping Uri="/Tasks" MappedUri="/Views/TaskView.xaml"/>
    </sdk:UriMapper>
</sdk:Frame.UriMapper>

And then within your page:

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        if (this.NavigationContext.QueryString.ContainsKey("Resource"))
        {
            ResourceViewModel rvm = ViewModelLocator.ResourceVMStatic;
            if (rvm != null)
                rvm.ResourceName = this.NavigationContext.QueryString["Resource"];
        }
        base.OnNavigatedTo(e);
    }

If you don't want to use pages, and want to use controls, you can do that, but you will have to provide the tracking manually. I would recommend using a view model just for your navigation, which can persist some data itself.

Ryan from Denver
Using a Frame instead of a ContentControl may be the way to go. There is no reason why I cannot turn these Controls into Pages. I am not sure why I was set on using Controls.
Shatterling