Can you use data binding to the Content property for the WPF framework?

I can use data binding to set the original content of a WPF frame, but subsequent changes to the associated property (implemented using the INotifyPropertyChange method) do not seem to change the content.

Also, does anyone know if binding directly to the Content property in this way will cause the related element to appear in the Frame or NavigationWindow log?

In some context: I understand that I should probably use NavigationService to interact with the frame, but I'm trying to follow the MVVM pattern. It seems like it would be much easier to bind data to the Content property ...

+3
source share
4 answers

Many in the WPF community agree that the built-in navigation system is broken. However, even if you used it, the binding of the Content property is not correct. If you want to use MVVM with navigation, you must combine it with the FrontController template, where the ViewModel sends a navigation request to the controller, which then solves this request for you. There are few examples of this concept because (as I mentioned earlier) many developers pass on the use of WPF's built-in navigation.

If you want to look at a very reliable navigation mechanism for WPF, look at nRoute. This is the port of the MVC routing mechanism for WPF.

+3
source

, , " " "TwoWay".

XAML:

<Frame Content={Binding Path=MyProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged} />

:

public class MyViewModel : INotifyPropertyChanging, INotifyPropertyChanged
{
  public Page MyProperty
  {
    get
    {
      return _viewModelPage;
    }

    set
    {
      this.OnPropertyChanging("MyProperty");
      _viewModelPage = value;
      this.OnPropertyChanged("MyProperty");
    }
  }
}
+5

- , NavigationService . INotifyPropertyChange, , , . , NavigationService.

0

. , ( Navigate()). , .

, DataContext , .

0

Source: https://habr.com/ru/post/1742506/


All Articles