private void VmOnPropertyChanged(object sender, PropertyChangedEventArgs args) { if (args.PropertyName == nameof(T4UserControlViewModel.Preview)) { var vm = (T4UserControlViewModel)DataContext; if (vm != null && vm.Errors?.Count == 0) { using (var stream = GenerateStreamFromString(vm.Preview)) PreviewTextEditor.Load(stream); } } else if (args.PropertyName == nameof(T4UserControlViewModel.Buffer)) { if (_documentChanging) { return; } var vm = (T4UserControlViewModel)DataContext; if (vm != null) { using (var stream = GenerateStreamFromString(vm.Buffer)) TextEditor.Load(stream); } } }
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs args) { if (args.NewValue != null) { var vm = (T4UserControlViewModel)args.NewValue; using (var stream = GenerateStreamFromString(vm.Buffer)) TextEditor.Load(stream); using (var stream = GenerateStreamFromString(vm.Preview)) PreviewTextEditor.Load(stream); vm.PropertyChanged += VmOnPropertyChanged; } }