There is an interface 1:
public interface IService { string TextString {get;set;} } There is a class 1 implementing this interface 1:
public class TextClass : IService, INotifyPropertyChanged { private string _textString ; public string TextString { get => _textString; set { _textString = value; OnPropertyChanged(); } } public TextClass { _textString = "XXXXX";} // Классическая реализация INotifyPropertyChanged // ..... } There is also an interface 2:
public interface IDataService<T> { T : TextClassLocal } There is a class 2 implementing interface 2:
public class DataService :IDataService<TextClass> { private TextClass _textClassLocal = new TextClass() public TextClass : TextClassLocal { get => _textClassLocal; set { _textClassLocal = value } } } There is a ViewModel:
public class MainViewModel : INotifyPropertyChanged { private _dataServise = new DataService(); private string _textMessage public string TextMessage { get => _dataService.TextClassLocal.TextString; set { _dataService.TextClassLocal.TextString = value; OnPropertyChanged(); } } // Классическая реализация INotifyPropertyChanged // ..... } Ust View in which:
<TextBlock Text={Binding TextMessage} /> The View DataContext is bound and the correct "XXXX" is displayed in the TextBlock at startup.
And now the most interesting, in any case for me;)
If the ViewModel to do the operation: TextString = "UUUU"; then the Text in the TextBlock will change to UUUU accordingly. All OK!
However, if done directly: _dataService.TextClassLocal.TextString = "UUUU"; then no changes will happen; (What could be the problem? How to get rid of it? In the combat implementation, the TextClass implements an Event that updates the TextString and these changes do not appear in TextBlock