MVVM with navigation

2 posts, 0 answers
  1. Alexandre
    Alexandre avatar
    10 posts
    Member since:
    Jun 2006

    Posted 26 Apr 2009 Link to this post

    Dear all,

    I'm building my solution using a Model view view model pattern.
    My navigation should be proformed on my Viewmodel but I do not have any reference from the view model to the view (xaml page it self).

    To perform my navigation I have a property (CurrentView) on my viemmodel and it is binded to the source property of my frame control on the view using something like:

    <Controls:RadFrameContainer x:Name="MainFrameContainer" Background="{StaticResource Blue5}" Grid.Column="2" Grid.Row="1">
                <Controls:RadFrame x:Name="MainFrame" Source="{Binding CurentView}"/>

    When I need to navigate I set the current view on my viewmodel to the desired page using something like:

    protected void Navigate()
           var viewtonavigate = new HomePage(); (1)
           viewtonavigate.Parameter = "myparameter";
           CurrentView = viewtonavigate;

    public RadPage CurrentView
           get{return currentview;}
                  currentview = value;

    My problem is that the constructor of the view HomePage is called twice.
    Once on (1) and then (2) before being displayed on the frame.
    and of course on the construction of (2) my Parameter is of course blank!!!
    Do you have any idea why the page gets constructed a second time?

    Thanks for your help.

  2. Bobi
    Bobi avatar
    513 posts

    Posted 27 Apr 2009 Link to this post

    Hi Alexandre,

    I noticed that you use the Source property of RadFrame. Using this property means that you navigate automatically to the source page without the need of adding some additional code. So, each time you use the Source property the page is initialized. You can refere to the following article:

    Also note that your CurrentView is of RadPage type and Source is of string type.
    Try to make a CurrentView string (this means that it is only a string representation of RadPage) if possible.

    If this does not solve your problem please send some sample code so that I can fix the problem.

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top