Click here to Skip to main content
15,895,787 members

Navigation History lost from Frame when TabItem Switching

jobyjames asked:

Open original thread
In my Application i Have two TabItem when i change Tab item then Frame History is lost, when i again select frame tab. I don't to destroy frame history.

Here is my Code

Xaml Side
XML
<sdk:TabControl>
    <sdk:TabItem>
        <StackPanel Orientation="Vertical">
            <StackPanel Orientation="Horizontal">
                <Button Content="Back" Height="25" x:Name="btnBack" Width="Auto" VerticalAlignment="Top" HorizontalAlignment="Left" Click="btnBack_Click" />
                <Button Content="Forward" Height="25" x:Name="btnForward" Width="Auto" VerticalAlignment="Top" HorizontalAlignment="Left" Click="btnForward_Click_1" />
                <Button Content="page1" Height="25" Width="Auto" VerticalAlignment="Top" HorizontalAlignment="Right" Click="Button_Click_1"/>
                <Button Content="page2" Height="25" Width="Auto" VerticalAlignment="Top" HorizontalAlignment="Right" Click="Button_Click_2"/>
                <Button Content="page3" Height="25" Width="Auto" VerticalAlignment="Top" HorizontalAlignment="Right" Click="Button_Click_3"/>
            </StackPanel>
            <navigation:Frame x:Name="mainFrame" Source="/Page2.xaml" Margin="0,20,0,0" Navigated="mainFrame_Navigated_1">
            </navigation:Frame>
        </StackPanel>
    </sdk:TabItem>
    <sdk:TabItem/>
</sdk:TabControl>

Code Side
C#
private void Button_Click_1(object sender, RoutedEventArgs e)
       {
           if (mainFrame.CanGoBack)
           {
               mainFrame.GoBack();
           }
       }

       private void Button_Click_2(object sender, RoutedEventArgs e)
       {
           if (mainFrame.CanGoForward)
           {
               mainFrame.GoForward();
           }
       }

       private void Button_Click_3(object sender, RoutedEventArgs e)
       {
           mainFrame.Navigate(new Uri("/Pages/Page2.xaml", UriKind.Relative));
           //mainFrame.Content = new Page3();
       }

       private void Button_Click_4(object sender, RoutedEventArgs e)
       {
           mainFrame.Navigate(new Uri("/Pages/Page3.xaml", UriKind.Relative));
           //mainFrame.Content = new Page2();
       }

       private void mainFrame_Navigated(object sender, NavigationEventArgs e)
       {
           if (mainFrame.CanGoBack)
               btnBack.IsEnabled = true;
           else
               btnBack.IsEnabled = false;

           if (mainFrame.CanGoForward)
               btnForward.IsEnabled = true;
           else
               btnForward.IsEnabled = false;
       }

Please help to Solve this Problem
Tags: Silverlight5

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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