History for View Based Navigation in Silverlight 3

by Administrator 22. September 2009 00:17

In my last article on View-based navigation, I mentioned that a useful Navigation History module could be built to work in concert.  This article discusses the design and implementation of that module. In this case my design goals are more straightforward:

  1. Allow the size of the navigation history to be set so as to control memory usage
  2. Allow going forwards and backwards in the history
  3. Allow inspection of the navigation history
  4. Allow aspects of navigation history to be bindable

Navigation History

As with the core navigation concepts I went over previously, there is some basic Navigation History built into the Frame class in Silverlight 3.  Since I’ve extended the core navigation concepts I can also add additional hooks for navigation.  As usual, I will first think of my design goals and craft an interface.

public interface INavigationHistory : INotifyPropertyChanged
{
    /// <summary>
    /// How many Views do we want to keep around?
    /// </summary>
    int HistorySize { get; set; }

    /// <summary>
    /// Go back one View, return the next active view
    /// </summary>
    IView GoBack();


    /// <summary>
    /// Go forward one view, return the next active view
    /// </summary>
    /// <returns></returns>
    IView GoForward();

    /// <summary>
    /// Can we go back based on current position?
    /// </summary>
    bool CanGoBack{get;}

    /// <summary>
    /// Can we go forward based on current position
    /// </summary>
    bool CanGoForward{get;}

    /// <summary>
    /// Called by clients to add a view to history
    /// </summary>
    /// <param name="v"></param>
    void Navigated(IView v);

    event Action<IView> NavigatedToView;

    event Action<IView> HistoryItemRemoved;

    /// <summary>
    /// Get the items in the current history, allow a jump to a specific point
    /// </summary>
    ObservableCollection<IView> CurrentHistory { get; }
    

    /// <summary>
    /// Go to a specific View in the history
    /// </summary>
    /// <param name="historyIndex"></param>
    void GoTo(IView v);

    /// <summary>
    /// Removes the most recent item
    /// </summary>
    /// <returns></returns>
    IView Pop();
}

Including INotifyPropertyChanged here means aspects of the navigation history will be bindable: CanGoBack, CanGoForward, and CurrentHistory.  The other parts of the interface should be self explanatory.

Binding to History

Using the previous Audi Fans demo, I can now make the navigation buttons in the lower right hand corner work.

navhist0

The XAML for creating these buttons is fairly simple, note the {Binding} aspects:

<StackPanel Orientation="Horizontal" Grid.Row="2" Margin="5" HorizontalAlignment="Right">
    <TextBlock Style="{StaticResource TextStyle}" >Navigation: </TextBlock>
    <Button x:Name="GoBack" IsEnabled="{Binding Path=History.CanGoBack}" Click="GoBack_Click">
        <Button.Content>
            <TextBlock Style="{StaticResource TextStyle}" Foreground="Black">&lt; Back</TextBlock>
        </Button.Content>
    </Button>                    
    <ComboBox x:Name="JumpCmb" DataContext="{Binding}" ItemsSource="{Binding Path=HistoryItems}" SelectedItem="{Binding Path=CurrentViewName, Mode=TwoWay}" Margin="10,0,10,0" Width="250" >                        
    </ComboBox>                     
    <Button x:Name="GoForward" IsEnabled="{Binding Path=History.CanGoForward}" Click="GoForward_Click">
        <Button.Content>
            <TextBlock Style="{StaticResource TextStyle}" Foreground="Black">Forward &gt;</TextBlock>
        </Button.Content>
    </Button>
</StackPanel>

In order to satisfy these bindings, the Navigation History implementation has been added to the MainViewModel for the front page.  You will note that I’m not binding directly to the History.CurrentHistory but that some additional fields have been added to MainViewModel:

ObservableCollection<string> _histItems;

/// <summary>
/// Silverlight crashes if you use a Page (IView) as a binding source.  Lame.
/// </summary>
public ObservableCollection<string> HistoryItems
{
    get
    {
        return _histItems;   
    }        
}


string _currentViewName;

public string CurrentViewName
{
    get { return _currentViewName; }
    set
    {                
        if (value != _currentViewName)
        {
            _currentViewName = value;
            OnPropertyChanged("CurrentViewName");

            if (_viewMap.ContainsKey(value))
            {   
                Navigation.GoTo(_viewMap[value]);
            }
        }
    }
}

Pit of failure: Silverlight does not seem to like having a Page object as a binding source except when doing Element binding.  This may be a low level implementation detail that’s just not supported, or it may be because the Pages in question are not visible and this causes some fundamental failure.

So there is a layer that maps IView names back to the INavigationHistory because Silverlight binding doesn’t like binding to a visual element that is not currently visible.

Conclusion

That’s pretty much it for Navigation History, be sure to read the previous article if you’d like to see how it fits in with everything else.  There are other directions you could take this, obviously.  If you are using some kind of Region manager you could scope the navigation to each region.  If you are concerned about memory usage, you could create a scheme to use WeakReferences and provide hooks to save just the ViewModel of an IView so that the IView itself could be reconstructed later. 

The updated source code for the HandWaver.AG guidance projects can be found here.

Tags:

Comments (1) -

mbt shoes
mbt shoes
11/3/2010 7:20:11 AM #

I just saw a articl about http://www.walkbay.com">MBT shoes in http://www.walkbay.com">walkbay.com.
  
http://www.walkbay.com">MBT stands for Masai Barefoot Technology.  The company that makes MBT Shoe (also known as the http://www.walkbay.com">anti shoe) is Swiss Masai.  The uniquely-designed, multi-layered, cured sole is designed to simulate walking in sand (similar to the natural walking environment of the Masai in Kenya).  This creates a natural, uneven walking surface and forces the body to use all the major and stabilsing muscle groups, thus training the whole body to move correctly.

does http://www.walkbay.com">MBT shoe really work?




http://www.walkbay.com">MBT shoe  http://www.walkbay.com">MBT shoes  http://www.walkbay.com">anti shoe  http://www.walkbay.com">anti shoes  http://www.walkbay.com">cheap MBT shoes  http://www.walkbay.com">MBT walking shoes  http://www.walkbay.com">walking shoes  http://www.walkbay.com">MBT shoes sale  http://www.walkbay.com">buy MBT shoes  http://www.walkbay.com">MBT shoes buy  http://www.walkbay.com">cheapest MBT shoes  http://www.walkbay.com">discount MBT shoes  http://www.walkbay.com">shape ups http://www.walkbay.com">shape up shoes http://www.walkbay.com">cheap MBT shoe  http://www.walkbay.com">massai shoes http://www.walkbay.com">shoes mbt http://www.walkbay.com">shoes anti http://www.walkbay.com">massai barefoot http://www.walkbay.com">MBT trainers http://www.walkbay.com">MBT trainer http://www.walkbay.com">MBT sneaker http://www.walkbay.com">MBT sneakers  http://www.walkbay.com">womens MBT shoes http://www.walkbay.com">women’s MBT shoes http://www.walkbay.com">women MBT shoes  http://www.walkbay.com">womens MBT  http://www.walkbay.com">women’s MBT http://www.walkbay.com">mbt women   http://www.walkbay.com">MBT women’s shoes http://www.walkbay.com">MBT shoes for women  http://www.walkbay.com">MBT shoes women http://www.walkbay.com">MBT shoes men http://www.walkbay.com">MEN MBT shoes  http://www.walkbay.com">men’s MBT shoes http://www.walkbay.com">mens MBT shoes   http://www.walkbay.com">men MBT  http://www.walkbay.com">MBT mens shoes http://www.walkbay.com">MBT shoes for men http://www.walkbay.com">MBT shoes men’s http://www.walkbay.com">MBT men’s shoes http://www.walkbay.com">MBT men  http://www.walkbay.com">MBT shoes men’s


www.walkbay.com/mbt-shoe-mbt-kimondo-men-s-c-78_88">MBT kimondo
http://www.walkbay.com">MBT sandal  
http://www.walkbay.com">MBT sandals
http://www.walkbay.com">women’s MBT sandals
http://www.walkbay.com/mbt-shoe-mbt-baridi-c-78_90">mbt baridi
http://www.walkbay.com/mbt-shoe-mbt-baridi-c-78_90">mbt baridi shoes
http://www.walkbay.com/mbt-shoe-mbt-baridi-c-78_90">women’s mbt baridi
http://www.walkbay.com/mbt-shoe-mbt-baridi-c-78_90">womens mbt shoes
http://www.walkbay.com/mbt-shoe-mbt-baridi-c-78_90">womens mbt
http://www.walkbay.com/mbt-shoe-mbt-changa-c-78_91">mbt changa
http://www.walkbay.com/mbt-shoe-mbt-changa-c-78_91">changa mbt
http://www.walkbay.com/mbt-shoe-mbt-changa-c-78_91">mbt changa shoes
http://www.walkbay.com/mbt-shoe-mbt-changa-c-78_91">women’s mbt changa
http://www.walkbay.com/mbt-shoe-mbt-changa-c-78_91">womens changa
http://www.walkbay.com/mbt-shoe-mbt-changa-c-78_91">women’s changa
http://www.walkbay.com/mbt-shoe-mbt-changa-c-78_91">women’s mbt shoes
www.walkbay.com/mbt-shoe-mbt-chapa-gtx-c-78_92">mbt chapa
www.walkbay.com/mbt-shoe-mbt-chapa-gtx-c-78_92">mbt chapa gtx
www.walkbay.com/mbt-shoe-mbt-chapa-gtx-c-78_92">chapa mbt
www.walkbay.com/mbt-shoe-mbt-chapa-gtx-c-78_92">mbt chapa shoes
www.walkbay.com/mbt-shoe-mbt-chapa-gtx-c-78_92">women’s mbt chapa
www.walkbay.com/mbt-shoe-mbt-chapa-gtx-c-78_92">womens mbt chapa
www.walkbay.com/mbt-shoe-mbt-chapa-gtx-c-78_92">men’s mbt chapa
www.walkbay.com/mbt-shoe-mbt-chapa-gtx-c-78_92">mens mbt chapa
www.walkbay.com/mbt-shoe-mbt-chapa-gtx-c-78_92">womens mbt shoes
www.walkbay.com/mbt-shoe-mbt-chapa-gtx-c-78_92">mens mbt shoes
http://www.walkbay.com/mbt-shoe-mbt-ema-c-78_93">mbt ema
http://www.walkbay.com/mbt-shoe-mbt-ema-c-78_93">womens mbt ema
http://www.walkbay.com/mbt-shoe-mbt-ema-c-78_93">womens mbt
http://www.walkbay.com/mbt-shoe-mbt-ema-c-78_93">mbt ema shoes
http://www.walkbay.com/mbt-shoe-mbt-ema-c-78_93">comfortable shoes
www.walkbay.com/.../women-s-mbt-ema-comfort-shoes-black-p-3417">comfort shoes
www.walkbay.com/mbt-shoe-mbt-fanaka-gtx-c-78_94">mbt fanaka
www.walkbay.com/mbt-shoe-mbt-fanaka-gtx-c-78_94">mbt fanaka gtx
www.walkbay.com/mbt-shoe-mbt-fanaka-gtx-c-78_94">mbt fanaka shoes
www.walkbay.com/mbt-shoe-mbt-fanaka-gtx-c-78_94">men’s mbt fanaka
www.walkbay.com/mbt-shoe-mbt-fanaka-gtx-c-78_94">mens mbt
www.walkbay.com/.../mbt-fanaka-gtx-mens-lace-up-shoes-chipper-brown-p-3421">lace up shoes
http://www.walkbay.com/mbt-shoe-mbt-fora-c-78_95">mbt fora
http://www.walkbay.com/mbt-shoe-mbt-fora-c-78_95">for a mbt
http://www.walkbay.com/mbt-shoe-mbt-fora-c-78_95">women’s mbt fora
http://www.walkbay.com/mbt-shoe-mbt-fora-c-78_95">mbt for a shoes
www.walkbay.com/.../mbt-fora-women-s-fitness-shoes-red-p-3423">fitness shoes
www.walkbay.com/.../women-mbt-fora-discount-shoe-white-p-3425">women mbt
http://www.walkbay.com/mbt-shoe-mbt-fumba-c-78_96">mbt fumba
http://www.walkbay.com/mbt-shoe-mbt-fumba-c-78_96">mbt fumba shoes
http://www.walkbay.com/mbt-shoe-mbt-fumba-c-78_96">men’s mbt fumba
http://www.walkbay.com/mbt-shoe-mbt-fumba-c-78_96"> mbt shoes men’s
www.walkbay.com/.../mbt-fumba-mens-shoes-sandals-cinnabar-p-3429">mens shoes sandals
http://www.walkbay.com/mbt-shoe-mbt-habari-c-78_97">mbt habari
http://www.walkbay.com/mbt-shoe-mbt-habari-c-78_97">mbt habari shoes
http://www.walkbay.com/mbt-shoe-mbt-habari-c-78_97">womens mbt habari
www.walkbay.com/.../mbt-women-mbt-habari-clogs-for-women-birch-p-3431">clog for women
http://www.walkbay.com/mbt-shoe-mbt-imara-c-78_99">mbt imara
http://www.walkbay.com/mbt-shoe-mbt-imara-c-78_99">mbt imara shoes
www.walkbay.com/mbt-shoe-mbt-karani-c-78_100">mbt karani
www.walkbay.com/mbt-shoe-mbt-karani-c-78_100">men mbt shoes
http://www.walkbay.com/mbt-shoe-mbt-kaya-c-78_101">mbt kaya
http://www.walkbay.com/mbt-shoe-mbt-kaya-c-78_101">mbt kaya shoes
http://www.walkbay.com/mbt-shoe-mbt-kaya-c-78_101">womens mbt kaya
http://www.walkbay.com/mbt-shoe-mbt-kaya-c-78_101">mbt womens shoes
www.walkbay.com/.../mbt-kaya-womens-mary-jane-navy-blue-mbt-womens-shoes-p-3439"> womens mary jane
www.walkbay.com/.../mbt-kaya-womens-mary-jane-navy-blue-mbt-womens-shoes-p-3439"> women’s mary jane
www.walkbay.com/mbt-shoe-mbt-kisumu-c-78_102">mbt kisumu
www.walkbay.com/mbt-shoe-mbt-kisumu-c-78_102">mens mbt kisumu
www.walkbay.com/mbt-shoe-mbt-kisumu-c-78_102">men’s mbt kisumu
www.walkbay.com/mbt-shoe-mbt-kisumu-c-78_102">womens mbt kisumu
www.walkbay.com/mbt-shoe-mbt-kisumu-c-78_102">women’s mbt kisumu
www.walkbay.com/.../mbt-kisumu-mens-clogs-brown-shoes-mbt-p-3447">shoes mbt
www.walkbay.com/.../mbt-kisumu-womens-casual-sandal-white-p-3455">womens casual sandal
http://www.walkbay.com/mbt-shoe-mbt-lami-c-78_103">mbt lami
http://www.walkbay.com/mbt-shoe-mbt-lami-c-78_103">lami mbt
www.walkbay.com/.../women-s-mbt-lami-mary-janes-purple-lami-mbt-p-3457">mary janes
http://www.walkbay.com/mbt-shoe-mbtwalk-c-78_104">mbt m.walk
http://www.walkbay.com/mbt-shoe-mbtwalk-c-78_104">mbt m.walk shoes
http://www.walkbay.com/mbt-shoe-mbtwalk-c-78_104">women’s mbt m.walk\
http://www.walkbay.com/mbt-shoe-mbtwalk-c-78_104">mens mbt m.walk
http://www.walkbay.com/mbt-shoe-mbtwalk-c-78_104">mbt mwalk
www.walkbay.com/.../mbtwalk-mens-black-sneakers-p-3462">mbt m. walk
www.walkbay.com/.../m-walk-mbt-women-trainer-pink-grey-p-3469">m.walk mbt
www.walkbay.com/.../mbt-walk-womens-shoes-trainers-grey-silver-p-3471">mbt walk
http://www.walkbay.com/mbt-shoe-mbt-panda-c-78_105">mbt panda
http://www.walkbay.com/mbt-shoe-mbt-panda-c-78_105">women’s mbt
www.walkbay.com/.../mbt-panda-mbt-womens-clogs-black-p-3479">womens clog
www.walkbay.com/mbt-shoe-mbt-salama-c-78_106">mbt salama
www.walkbay.com/mbt-shoe-mbt-salama-c-78_106">mbt women’s shoes
www.walkbay.com/mbt-shoe-mbt-salama-c-78_106">women’s mbt
www.walkbay.com/mbt-shoe-mbt-sapatu-c-78_107">mbt sapatu
www.walkbay.com/mbt-shoe-mbt-sapatu-c-78_107">womens mbt sapatu
www.walkbay.com/.../mbt-sandal-women-s-mbt-sapatu-white-p-3485">mbt sandal
www.walkbay.com/.../mbt-sandals-men-s-mbt-sapatu-white-p-3487">mbt sandals
www.walkbay.com/mbt-shoe-mbt-sapatu-c-78_107">mbt sawa
www.walkbay.com/mbt-shoe-mbt-sapatu-c-78_107">mbt mary jane
www.walkbay.com/mbt-shoe-mbt-sapatu-c-78_107">mbt women’s
www.walkbay.com/mbt-shoe-mbt-sapatu-c-78_107">mbt shuguli
www.walkbay.com/mbt-shoe-mbt-sapatu-c-78_107">mbt shuguli gtx
www.walkbay.com/mbt-shoe-mbt-sapatu-c-78_107">mbt men
www.walkbay.com/.../mbt-shoes-womens-sirima-mary-janes-shoes-black-p-3491">mbt sirima
www.walkbay.com/.../mbt-shoes-womens-sirima-mary-janes-shoes-black-p-3491">mbt shoes
www.walkbay.com/.../mbt-shoes-womens-sirima-mary-janes-shoes-black-p-3491">mary janes shoes
www.walkbay.com/mbt-shoe-mbt-sport-2-c-78_1111">mbt sport 2
www.walkbay.com/mbt-shoe-mbt-sport-2-c-78_1111">mbt sport
www.walkbay.com/mbt-shoe-mbt-sport-2-c-78_1111">mbt sport shoes
www.walkbay.com/mbt-shoe-mbt-sport-2-c-78_1111"> sport mbt
http://www.walkbay.com/mbt-shoe-mbt-sport-c-78_112">mbt sport
http://www.walkbay.com/mbt-shoe-mbt-sport-c-78_112">sport mbt
http://www.walkbay.com/mbt-shoe-mbt-sport-c-78_112">women’s mbt sport
http://www.walkbay.com/mbt-shoe-mbt-sport-c-78_112">men’s mbt sport
www.walkbay.com/.../mbt-sport-women-s-walking-shoe-white-p-3501">women’s walking shoe
http://www.walkbay.com/mbt-shoe-mbt-staka-c-78_113">mbt staka
www.walkbay.com/.../mbt-men-s-shoes-tariki-mens-oxfords-black-p-3504">mbt tariki
www.walkbay.com/.../mbt-men-s-shoes-tariki-mens-oxfords-black-p-3504">tariki mbt
www.walkbay.com/.../mbt-men-s-shoes-tariki-mens-oxfords-black-p-3504">mbt men’s shoes
www.walkbay.com/.../mbt-men-s-shoes-tariki-mens-oxfords-black-p-3504">mens oxfords
www.walkbay.com/.../womens-mbt-shoe-tembea-black-p-3505">mbt tembea
www.walkbay.com/.../womens-mbt-shoe-tembea-black-p-3505">mbt shoe
www.walkbay.com/.../womens-mbt-shoe-tembea-black-p-3505">womens mbt shoe
www.walkbay.com/mbt-shoe-mbt-tunisha-c-78_117">mbt tunisha
www.walkbay.com/mbt-shoe-mbt-tunisha-c-78_117">tunisha mbt
www.walkbay.com/mbt-shoe-mbt-tunisha-c-78_117">mbt tunisha shoes
www.walkbay.com/mbt-shoe-mbt-tunisha-c-78_117">mbt womens shoes
www.walkbay.com/.../mbt-womens-shoes-mbt-tunisha-maryjane-shoes-black-p-3508">maryjane shoes
http://www.walkbay.com/mbt-shoe-mbt-unono-c-78_118">mbt unono
http://www.walkbay.com/mbt-shoe-mbt-voi-c-78_119">mbt voi
www.walkbay.com/.../mbt-voi-womens-trainer-black-p-3511">womens trainer
www.walkbay.com/.../mbt-voi-womens-trainers-white-p-3512">womens trainers

Reply

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


About the author

Damon Payne is a Microsoft MVP specializing in Smart Client solution architecture. 

INETA Community Speakers Program

Month List

Page List

flickr photostream