BindingEx pression路径错误 [英] BindingExpression path error

查看:117
本文介绍了BindingEx pression路径错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多类似的问题,我已经尝试了一些从这些问题的答案,但到目前为止没有什么帮助。我不明白的错误消息实际上是指。该错误消息;

  System.Windows.Data错误:40:BindingEx pression路径错误:'CategoryModel
在'对象'''字符串没有找到属性(哈希code = -57655201)。
BindingEx pression:路径= CategoryModel.CategoryList;的DataItem ='字符串'
(哈希code = -57655201);目标元素是'TextBlock的'(名称=''); target属性
文本(类型'字符串')

所属分类中包含有门类齐全的字符串列表(从调试选中)。我的XAML是低于,

 < ListView的X:名称=categoryListView的Horizo​​ntalAlignment =左WIDTH =56HEIGHT =156
              的ItemsSource ={绑定路径= CategoryModel.CategoryList}
              的DisplayMemberPath =CategoryModel.CategoryList
              的SelectedValue ={绑定路径= CategoryModel.SelectedCategory}
              VerticalAlignment =评出的RenderTransformOrigin =0.5,0.5>
< /&的ListView GT;

在XAML设计看起来不错,应用软件运行良好,但没有得到填补。该所属分类应该在初始化时被填充。它实际上是填补但ListView控件不显示任何东西。

编辑:

该CategoryModel;

 使用系统;
使用System.Collections.Generic;
使用System.Collections.ObjectModel;
使用System.ComponentModel;
使用System.Linq的;
使用System.Text;
使用System.Threading.Tasks;命名空间RecorderApp.Model
{
公共类CategoryModel:INotifyPropertyChanged的
{
    私人字符串_selectedCategory;
    私人字符串_recordTitle;
    私人字符串_systemInfoLabel;
    私人的ObservableCollection<串GT; _categoryList;    公众的ObservableCollection<串GT;所属分类
    {
        {返回_categoryList; }        组
        {
            如果(_categoryList!=值)
            {
                _categoryList =价值;
                OnPropertyChanged(所属分类);
            }
        }
    }    公共字符串SystemInfoLabel
    {
        {返回_systemInfoLabel; }        组
        {
            如果(_systemInfoLabel!=值)
            {
                _systemInfoLabel =价值;
                OnPropertyChanged(SystemInfoLabel);
            }
        }
    }    公共字符串SelectedCategory
    {
        {返回_selectedCategory; }        组
        {
            如果(_selectedCategory!=值)
            {
                _selectedCategory =价值;
                OnPropertyChanged(SelectedCategory);
            }
        }
    }    公共字符串RecordTitle
    {
        {返回_recordTitle; }
        组
        {
            _recordTitle =价值;
            OnPropertyChanged(RecordTitle);
        }
    }    公共事件PropertyChangedEventHandler的PropertyChanged;    私人无效OnPropertyChanged(字符串propertyName的)
    {
        如果(的PropertyChanged!= NULL)
        {
            的PropertyChanged(这一点,新PropertyChangedEventArgs(propertyName的));
        }
    }
}
}


解决方案

的DisplayMemberPath 绑定导致错误,并在你的情况应该被完全删除,因为它不是必要的。

要使用的DisplayMemberPath ,你需要能够引用属性如 ListView.ItemsSource [X] .SomeProperty ,其中 SomeProperty 将是你的的DisplayMemberPath

您收到此错误,因为你的的ItemsSource 列表<弦乐> 字符串不包含一个名为属性 CategoryModel

要说明你有确切的绑定错误:


  

System.Windows.Data错误:40:BindingEx pression路径错误:'CategoryModel
  在'对象'''字符串没有找到属性(哈希code = -57655201)。
  BindingEx pression:路径= CategoryModel.CategoryList;的DataItem ='字符串'
  (哈希code = -57655201);目标元素是'TextBlock的'(名称=''); target属性
  文本(类型'字符串')​​



  • 这行意味着它不能找到属性 CategoryModel 的对象字符串


      

    BindingEx pression路径错误:'CategoryModel
      财产上的'对象'''串'(哈希code = -57655201)

    未找到

  • 这行包含正在引发错误的结合前pression的路径属性


      

    BindingEx pression:路径= CategoryModel.CategoryList;



  • 此行​​告诉您源对象的绑定抛出错误(通常是的DataContext


      

    的DataItem ='字符串'
      (哈希code = -57655201);



  • 和此行意味着它未能属性文本文本框(绑定的DisplayMemberPath 是制作一个快捷方式的ItemTemplate 一个的TextBlock ,与它的文本绑定到的DisplayMemberPath 属性)


      

    目标元素是'TextBlock的'(名称=''); target属性
      文本(类型'字符串')​​



因此​​,为了把它放在一起,这是告诉你,它正试图绑定 TextBox.Text {绑定路径= CategoryModel.CategoryList } ,但是的DataContext 后面的文本框的类型为字符串字符串没有一个叫做物业 CategoryModel

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));
        }
    }
}
}

解决方案

Your DisplayMemberPath binding is causing the error, and in your case should be removed entirely since it is not needed.

To use DisplayMemberPath, you need to be able to reference the property like ListView.ItemsSource[X].SomeProperty, where SomeProperty would be your DisplayMemberPath

You are getting this error because your ItemsSource is a List<String>, and String does not contain a property called CategoryModel.

To explain the exact binding error you have:

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')

  • This line means it can't find the property CategoryModel on the object String

    BindingExpression path error: 'CategoryModel' property not found on 'object' ''String' (HashCode=-57655201)'

  • This line contains the Path property for the binding expression that is throwing the error

    BindingExpression:Path=CategoryModel.CategoryList;

  • This line tells you the Source object for the binding that is throwing the error (typically the DataContext)

    DataItem='String' (HashCode=-57655201);

  • And this line means it is failing to bind the property Text on a TextBox (DisplayMemberPath is a shortcut way of making the ItemTemplate a single TextBlock, with it's Text bound to the DisplayMemberPath property)

    target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')

So to put it all together, it is telling you that it is trying to bind TextBox.Text to {Binding Path=CategoryModel.CategoryList}, however the DataContext behind the TextBox is of type String, and String does not have a property called CategoryModel

这篇关于BindingEx pression路径错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆