My MainView
has a ViewModel called MainViewModel
. MainViewModel
creates a dialog and I want the dialogs ViewModel to be the already existing MainViewModel
To create the dialog from the MainViewModel
I do
var MyInnerDlg = new MyInnerDlgView();
MyInnerDlg.DataContext = this;
MyInnerDlg.ShowDialog();
In the dialog I have a ListBox
which I bind to a collection from my MainViewModel
public ObservableCollection<MyItemViewModel> MyList { get; set; }
XAML of the dialog
<Border Margin="5" BorderThickness="2">
<ListBox ItemsSource="{Binding MyList}" DisplayMemberPath="{Binding MyList.Name}" />
</Border>
The Name
property is in MyItemViewModel
. With the above code I get the error:
Name property not found in MainViewModel.
How can I refer to each of the items Name property?