Click here to Skip to main content
15,887,844 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys I have a WPF application that is using MVM pattern. In the application I have a frame that host my page a and b, however when I change view from page a to b, and try to change my view back to page a, it does not bring me a new page instead it brings back page a with its old state. How can I stop that? Below is my code for both my xaml and view model

xaml

HTML
<MenuItem Header="Operator" Visibility="{Binding Path=MenuVisibility, Converter={StaticResource BooleanToVisibilityConverter}}"
                          Command="{Binding Path=ViewMenuCommand}" />

<Frame Grid.Row="1" Name="MainAPpFrame" NavigationUIVisibility="Hidden"
                Source="{Binding Path=DisplayPage, Mode=TwoWay}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" />


my view model

C#
private Page displayPage;

        public Page DisplayPage
        {
            get
            {
                return displayPage;
            }
            set
            {
                if (displayPage == value)
                {
                    return;
                }

                this.displayPage = value;
                base.OnPropertyChanged("DisplayPage");
            }
        }

public ICommand ViewMenuCommand
        {
            get
            {
                if (_operatorViewMenuCommand == null)
                {
                    _operatorViewMenuCommand = new RelayCommand(
                        param => this.ProcessNavRequest());
                }
                return _operatorViewMenuCommand;
            }
        }

private void ProcessNavRequest()
        {
            //string uri = String.Format("/View/{0}", parameter);
            this.DisplayPage = new OperatorView();
        }
Posted
Updated 31-May-17 8:13am

1 solution

private Page _displayPage;

       public Page DisplayPage
       {
           get
           {
               return _displayPage;
           }
           set
           {
               if (Equals(_displayPage, value))
               {
                   return;
               }

               this._displayPage = value;
               OnPropertyChanged("DisplayPage");
           }
       }


       private RelayCommand _operatorViewMenuCommand;
       public ICommand ViewMenuCommand
       {
           get
           {
               if (_operatorViewMenuCommand == null)
               {
                   _operatorViewMenuCommand = new RelayCommand(param => this.ProcessNavRequest(DisplayPage));
               }
               return _operatorViewMenuCommand;
           }
       }
       public void ProcessNavRequest(Page page)
       {
           //string uri = String.Format("/View/{0}", parameter);
           this.DisplayPage = page;
       }


I call from myCommand

StartScreenViewModel.ProcessNavRequest(new ImportForm());


But it does not remember the navigation
 
Share this answer
 
Comments
Richard Deeming 31-May-17 16:56pm    
If you want to ask a question, then ASK A QUESTION[^].

DO NOT post your question as a "solution" to someone else's question!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900