Hello. There is a WPF MVVM window. There is a DataGrid in the window, one of the columns in the grid contains a ListBox , the data of which the ViewModel must provide.
<DataGrid Name="OperativeScheduleTable" Grid.Row="1" ItemsSource="{Binding Path= OperativeSchedules}"> <DataGrid.Columns> <DataGridTextColumn Width="Auto" Binding="{Binding Path=Id}" Header="Id" IsReadOnly="True"/> <DataGridTemplateColumn Header="Станция отправления"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <ListBox ItemsSource="{Binding Path=Stations}" Padding="5"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Width="50" Text="{Binding Path=Name}" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid> ViewModel:
public class RailwayStationEditViewModel : Screen { private readonly IUnitOfWork _unitOfWork; public RailwayStation RailwayStations { get; private set; } public ObservableCollection<Station> Stations { get; set; } //Сюда нужно Байндится!!! public RailwayStationEditViewModel(IUnitOfWork unitOfWork, RailwayStation railwayStation) { _unitOfWork = unitOfWork; RailwayStations = railwayStation; Stations = new ObservableCollection<Station>(RailwayStations.Stations.ToList()); } } It is necessary to specify most likely through DataContext:
<ListBox ItemsSource="{Binding Path=Stations, указать что коллекция находится во ViewModel}" Padding="5"> And now the search for the Stations collection is done in the OperativeSchedules element ( DataGrid bending)