views:

21

answers:

1

Hi,

I have three pages, and to navigate to each page, I'm binding a property to the Source property of the Frame. It works pretty fine if I just navigate the pages normally, but after calling the GoBack method, the Frame suddenly stopped working. If I set a uri to the Source property directly instead of using binding, it works fine though, I'm actually implementing using MVVM, so I don't want to set the Source property directly.

--xaml--

  <navigation:Frame x:Name="_frame" Source="{Binding CurrentPage}"/>

--Code behind--

    Uri _currentPage;
    public Uri CurrentPage
    {
        get { return _currentPage; }
        set
        {
            _currentPage = value;
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("CurrentPage"));
        }
    }

    // back
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        if ( _frame.CanGoBack)
            _frame.GoBack();
    }

    // test1
    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        CurrentPage = new Uri("/TestPage1.xaml", UriKind.Relative);
    }

    // test2
    private void Button_Click_2(object sender, RoutedEventArgs e)
    {
        CurrentPage = new Uri("/TestPage2.xaml", UriKind.Relative);
    }

    // test3
    private void Button_Click_3(object sender, RoutedEventArgs e)
    {
        CurrentPage = new Uri("/TestPage3.xaml", UriKind.Relative);
    }

Does anyone know how to work around this problem? I've tried several ways, but nothing works for me.

Thanks in advance,
Yoo

A: 

After testing for a while, I found a reason why it doesn't work. The problem was that the binding to the Source property is dropped after calling GoBack for some reason. So if you want to do that, set the binding again programmatically like the following.

_frame.SetBinding(Frame.SourceProperty, new Binding() { Source = this, Path = new PropertyPath("CurrentPage") });

But you should consider when to set the binding again otherwise it doesn't works properly.

Yoo

Yoo Matsuo