I have a viewmodel attached to a view class, whose control properties results in a binding error 40. The view is a user control acting as an ItemsControl.
<ItemsControl ItemsSource="{Binding TaskList}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:TaskItemUserControl />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
The ItemsSource is binded to an ObservableCollection in the viewmodel..
using Helpers.System;
using System.Collections.ObjectModel;
namespace ApplicationCore
{
/// <summary>
/// View model container is a list view for task list item controls
/// </summary>
public class TaskListViewModel : BaseViewModel
{
#region properties
/// <summary>
/// Runtime data to show in the task control list
/// </summary>
public ObservableCollection<TaskItemViewModel> TaskList =
new ObservableCollection<TaskItemViewModel>();
#endregion
}
}
When navigating to the page hosting the ItemsControl, a binding error appears.
System.Windows.Data Error: 40 : BindingExpression path error: 'TaskList' property not found on 'object' ''TaskListViewModel' (HashCode=3416986)'. BindingExpression:Path=TaskList; DataItem='TaskListViewModel' (HashCode=3416986); target element is 'ItemsControl' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')
The source used to exist in a single WPF application template created in visual studio 2015, probably targetting .NET 4.6.1. This source worked. The property is public, and instantiated in the viewmodel.
Since moving the view model to a portable C# library targetting 4.5.1 in Visual Studio 2017, the binding error has appeared. As a result, invoking ObservableCollection.Add on the Application.Current dispatcher thread does not result in the ItemsControl updating. The application project is a WPF template created in Visual Studio 2017 targetting .NET 4.6.1. This includes WindowsBase, PresentationCore etc. The dlls exist in bin, are up-to-date and resolved correctly at runtime. No exceptions appear in the debug console.
Is the assembly separation causing a problem I'm not aware of? Is there a change in the environment that may have caused this (VC compiler?), or framework (IEnumerable vs ObservableCollection) even though the .NET framework is the same (I assume backward compatibility as a minimum).