WPF Error 40 BindingExpression path error: property not found on 'object'

后端 未结 9 607
一整个雨季
一整个雨季 2020-11-27 16:04

I\'m banging my head on my desk with this binding error.. I have checked several of the postings for the BindingExpression path error and cannot see anything t

相关标签:
9条回答
  • 2020-11-27 16:38

    I had a similar experience, the ItemsSource binding on a Combobox did not work.

    In my case it was a minor mistake, but a difficult one to track until I enabled trace messages.

    I simply forget to turn my List into a property :(

    // NOPE:
    public List<string> Versions;
    // YEP:
    public List<string> Versions { get; set; }
    

    Maybe this helps someone...

    0 讨论(0)
  • 2020-11-27 16:43

    Few things to check

    1.assign values in properties before InitializeComponent in constructor

     public partial class SampleClass: UserControl
    {
        public SampleClass()
        {
            ScenarioHeight = System.Windows.SystemParameters.WorkArea.Height - 350;
            InitializeComponent();           
    
    
        }
    
        public double ScenarioHeight  { get;set;}
    

    2.if its a usercontrol make sure to add userControl as Element in the binding

     <ScrollViewer Name="sv" Height="{Binding Path=ScenarioHeight, ElementName=ucSampleClass}" >
    
    0 讨论(0)
  • 2020-11-27 16:47

    I wrote some other SO answer recently about how to read the binding errors so they make more sense. To summarize, add line breaks to your error message on the colons and semi-colons, and read it from the bottom up.

    Your error message is:

    • System.Windows.Data Error: 40 :
      • BindingExpression path error: 'ConfigurationModel' property not found on 'object' ''IncrementingTextBox' (Name='video_length_textbox')'.
      • BindingExpression:Path=ConfigurationModel.DontUseSensorLength;
    • DataItem='IncrementingTextBox' (Name='video_length_textbox');
    • target element is 'IncrementingTextBox' (Name='video_length_textbox');
    • target property is 'IsEnabled' (type 'Boolean')

    This can be read from the bottom up as:

    • The binding failing is the IsEnabled property of an element of type IncrementingTextBox (named video_length_textbox).

    • The DataItem (DataContext) of the element is an object of type IncrementingTextBox named video_length_textbox

    • The binding expression it is trying to find is ConfigurationModel.DontUseSensorLength

    • And the problem the binding is having is that the ConfigurationModel property is not found on the data context object IncrementingTextBox

    So your DataContext for "video_length_textbox" is set to itself, and your IncrementingTextBox class does not have a public property called ConfigurationModel

    Since I don't see you setting the DataContext for your IncrementingTextBox anywhere in your XAML, check out the code for your IncrementingTextBox class. The most likely case is you are setting the DataContext to itself in either the Constructor

    this.DataContext = this;
    

    or the XAML

    DataContext="{Binding RelativeSource={RelativeSource Self}}"
    
    0 讨论(0)
提交回复
热议问题