有很多类似的问题,我已经尝试了一些这些问题的答案,但迄今没有任何帮助。我不明白这个错误信息实际上是什么意思。错误信息是;BindingExpression路径错误
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包含已满的类别的字符串列表(从调试中检查)。我的xaml低于,
<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>
xaml设计看起来不错,应用程序运行正常,但没有填充。 categoryList应该在初始化时填充。它实际上被填充,但listView不显示任何东西。
编辑:
该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));
}
}
}
}
我认为您对SelectedValue的使用是错误的。尝试用SelectedValuePath替换它 – iltzortz
将其更改并且错误是相同的。你是否也需要这些模型? – mechanicum
描述你想做什么,因为它不清楚。你想成为Itemssource显示什么和选择什么值。我问这些是因为:CategoryList是一个可观察的字符串集合。由于您将ItemSource设置为此Observable集合DisplayMemberPath和SelectedValue(Path或Not)是没有用的。 – iltzortz