Использование Microsoft Visual studio в проекте WPF. У меня есть ListBox, который ItemsSource установлен в список объектов, называемых LuhFile. LuhFile содержит общедоступную строку displayName. Я хочу ListBox для отображения DISPLAYNAME, однако, когда я установил DisplayName к DisplayMemberPath в ListBox, я получаю эту ошибку:Свойство ListBox DisplayMemberPath не найдено
System.Windows.Data Error: 40 : BindingExpression path error: 'displayName' property not found on 'object' ''LuhFile' (HashCode=61470144)'. BindingExpression:Path=displayName; DataItem='LuhFile' (HashCode=61470144); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
C# MainWindow
private List<LuhFile> luhFileList;
public MainWindow()
{
InitializeComponent();
luhFileList = new List<LuhFile>();
luhFileList.Add(new LuhFile("testPath", "testName", "testDisplay"));
luhListBox.ItemsSource = luhFileList;
}
C# LuhFile
class LuhFile
{
public string path;
public string fileName;
public string displayName;
public LuhFile(string givenPath, string givenFileName, string givenDisplayName)
{
path = givenPath;
fileName = givenFileName;
displayName = givenDisplayName;
}
}
XAML
<ListBox x:Name="luhListBox" MinHeight="100" MaxHeight="130" DisplayMemberPath="displayName" />