Почему родительская ViewModel в конечном итоге становится нулевой?C#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Почему родительская ViewModel в конечном итоге становится нулевой?

Сообщение Anonymous »


Почему родительская ViewModel в дочерней модели становится нулевой?

Для взаимодействия между дочерней и родительской ViewModel я передал ссылку на родительскую ViewModel в дочернюю ViewModel.

Когда я открываю окно ManagerIndexesViewModel.IndexesViewModel во время отладки, элемент ManagerIndexesViewModel, расположенный в IndexesViewModel, не равен нулю .

Когда я ввожу строку в IndexesView.DataGrid, то в свойстве SelectedIndexCalculation я получаю this.managerIndexesViewModel = null (в строке this.managerIndexesViewModel.SelectedIndexCalculation = SelectedIndexCalculation;).

IndexesViewModel

public IndexCalculation SelectedIndexCalculation { получить {вернуть выбранныйIndexCalculation; } набор { selectedIndexCalculation = значение; Debug.WriteLine($"--- --- --- --- --- --- --- --- ---"); Debug.WriteLine($"IndexesViewModel --selectedIndexCalculation -- {selectedIndexCalculation.Name}"); this.managerIndexesViewModel.SelectedIndexCalculation = SelectedIndexCalculation; RaisePropertyChanged(nameof(SelectedIndexCalculation)); } } Проект: https://github.com/jhon65496/WpfFrmApp1QPublic

ManagerIndexesViewModel

публичный класс ManagerIndexesViewModel: BaseVM { IndexesViewModel indexesViewModel; //. Код.... публичный ManagerIndexesViewModel() { // Модель просмотра this.indexesViewModel = новая IndexesViewModel(this); // Код // ..... // Вид IndexesView = this.indexesViewModel; // Код // ..... SelectedIndexCalculation = indexesViewModel.SelectedIndexCalculation; } IndexesViewModel

публичный класс IndexesViewModel: BaseVM { общественный ManagerIndexesViewModel ManagerIndexesViewModel; общедоступная IndexesViewModel (ManagerIndexesViewModel ManagerIndexesViewModel) { this.managerIndexesViewModel = ManagerIndexesViewModel; ЗагрузитьДанныеТест(); } публичные индексыViewModel() { ЗагрузитьДанныеТест(); } частный ObservableCollection расчетИндексы; public ObservableCollection СalculationIndexs { получить {вернуть расчетIndexs; } набор { расчетИндексы = значение; RaisePropertyChanged(nameof(СalculationIndexs)); } } частный IndexCalculation selectedIndexCalculation; public IndexCalculation SelectedIndexCalculation { получить {вернуть выбранныйIndexCalculation; } набор { selectedIndexCalculation = значение; Debug.WriteLine($"--- --- --- --- --- --- --- --- ---"); Debug.WriteLine($"IndexesViewModel --selectedIndexCalculation -- {selectedIndexCalculation.Name}"); RaisePropertyChanged(nameof(SelectedIndexCalculation)); } }
Изображение



Изображение



Изображение



Изображение

Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»