There are many similar questions and I've tried a number of answers from those questions but so far nothing helps. I do not understand what the error message means actually. The error message is;
System.Windows.Data Error: 40 : BindingExpression path error: 'CategoryModel'
property not found on 'object' ''String' (HashCode=-57655201)'.
BindingExpression:Path=CategoryModel.CategoryList; DataItem='String'
(HashCode=-57655201); target element is 'TextBlock' (Name=''); target property is
'Text' (type 'String')
CategoryList contains a string list of categories which are full (checked from debug). My xaml is below,
<ListView x:Name="categoryListView" HorizontalAlignment="Left" Width="56" Height="156"
ItemsSource="{Binding Path=CategoryModel.CategoryList}"
DisplayMemberPath="CategoryModel.CategoryList"
SelectedValue="{Binding Path=CategoryModel.SelectedCategory}"
VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5">
</ListView>
The xaml design looks ok, application runs fine but nothing gets filled. The categoryList is supposed to be filled at initialization. It is filled actually but listView doesn't show anything.
EDIT:
The CategoryModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RecorderApp.Model
{
public class CategoryModel : INotifyPropertyChanged
{
private String _selectedCategory;
private String _recordTitle;
private String _systemInfoLabel;
private ObservableCollection<String> _categoryList;
public ObservableCollection<String> CategoryList
{
get { return _categoryList; }
set
{
if (_categoryList != value)
{
_categoryList = value;
OnPropertyChanged("CategoryList");
}
}
}
public String SystemInfoLabel
{
get { return _systemInfoLabel; }
set
{
if (_systemInfoLabel != value)
{
_systemInfoLabel = value;
OnPropertyChanged("SystemInfoLabel");
}
}
}
public String SelectedCategory
{
get { return _selectedCategory; }
set
{
if (_selectedCategory != value)
{
_selectedCategory = value;
OnPropertyChanged("SelectedCategory");
}
}
}
public string RecordTitle
{
get { return _recordTitle; }
set
{
_recordTitle = value;
OnPropertyChanged("RecordTitle");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…