У меня есть Scrollviewer , внутри которого есть элемент emitycontrol , внутри которого я хочу отобразить пользовательские представления и передавать данные в них с помощью привязки.
Отдельные элементы имеют DeviceListIteMView Type, который содержит DeviceListiTemViewModel ViewModel свойство. Я, кажется, устанавливаю emitssource и itemtemplate правильно, так как Scrollviewer отображает правильный объем DeviceListiTemView , но я не могу выяснить, как передавать данные в DeviceListiTemView. .ViewModel
Чего мне не хватает?
DeviceListView.xaml:
< /code>
DeviceListView.xaml.cs:
public partial class DeviceListView : UserControl
{
DeviceListViewModel viewModel = new DeviceListViewModel();
public DeviceListView()
{
InitializeComponent();
SetupBindings();
}
private void SetupBindings()
{
var itemViewFactory = new FrameworkElementFactory(typeof(DeviceListItemView));
DataTemplate dataTemplate = new DataTemplate();
dataTemplate.DataType = typeof(DeviceListItemViewModel);
dataTemplate.VisualTree = itemViewFactory;
items.ItemsSource = viewModel.items;
items.ItemTemplate = dataTemplate;
}
}
< /code>
DeviceListViewModel.cs:
internal class DeviceListViewModel
{
public List items { get; set; } = new List();
public DeviceListViewModel()
{
SetupSubscriptions();
}
private void SetupSubscriptions()
{
// updates items property
}
}
< /code>
DeviceListItemView.xaml.cs:
public partial class DeviceListItemView : UserControl
{
public DeviceListItemViewModel ViewModel = new DeviceListItemViewModel();
public DeviceListItemView()
{
InitializeComponent();
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... emscontrol