This is a migrated thread and some comments may be shown as answers.

MVVM with navigation

1 Answer 166 Views
Navigation
This is a migrated thread and some comments may be shown as answers.
Alexandre
Top achievements
Rank 2
Alexandre asked on 26 Apr 2009, 07:36 AM
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}"/>
        </Controls:RadFrameContainer>

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;}
       set{
              currentview = value;
              RaisePropertyChange("CurrentView");(2)
             }
}

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.

Alex.

1 Answer, 1 is accepted

Sort by
0
Bobi
Telerik team
answered on 27 Apr 2009, 08:27 AM
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:

http://www.telerik.com/help/silverlight/navigation-radframe.html

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.

Regards,
Boryana
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.
Tags
Navigation
Asked by
Alexandre
Top achievements
Rank 2
Answers by
Bobi
Telerik team
Share this question
or