Ticket T484335
Visible to All Users

System.Windows.Data Error: 40 : BindingExpression path error:

created 8 years ago

Hi

I have a number of single object views built by the scaffolding wizard which has created lookupedits for related entities.

When I build and run the application I see the following:

System.Windows.Data Error: 40 : BindingExpression path error: 'FishingAreasLookup' property not found on 'object' ''VesselViewModel_a908bd3c_36b3_4fed_9e8b_881df03c7ecf' (HashCode=64403057)'. BindingExpression:Path=FishingAreasLookup; DataItem='VesselViewModel_a908bd3c_36b3_4fed_9e8b_881df03c7ecf' (HashCode=64403057); target element is 'LookUpEdit' (Name=''); target property is 'UnderlyingObject' (type 'Object')
System.Windows.Data Error: 40 : BindingExpression path error: 'FishingZonesLookup' property not found on 'object' ''VesselViewModel_a908bd3c_36b3_4fed_9e8b_881df03c7ecf' (HashCode=64403057)'. BindingExpression:Path=FishingZonesLookup; DataItem='VesselViewModel_a908bd3c_36b3_4fed_9e8b_881df03c7ecf' (HashCode=64403057); target element is 'LookUpEdit' (Name=''); target property is 'UnderlyingObject' (type 'Object')
System.Windows.Data Error: 40 : BindingExpression path error: 'DeductionId' property not found on 'object' ''VesselViewModel_a908bd3c_36b3_4fed_9e8b_881df03c7ecf' (HashCode=64403057)'. BindingExpression:Path=DeductionId; DataItem='VesselViewModel_a908bd3c_36b3_4fed_9e8b_881df03c7ecf' (HashCode=64403057); target element is 'LookUpEdit' (Name=''); target property is 'UnderlyingObject' (type 'Object')
System.Windows.Data Error: 40 : BindingExpression path error: 'ContactTypesLookup' property not found on 'object' ''ContactViewModel_1b9cecb8_4129_4573_9da6_3c4548284e6c' (HashCode=3633470)'. BindingExpression:Path=ContactTypesLookup; DataItem='ContactViewModel_1b9cecb8_4129_4573_9da6_3c4548284e6c' (HashCode=3633470); target element is 'LookUpEdit' (Name='ContactTypeLookupEdit'); target property is 'UnderlyingObject' (type 'Object')
System.Windows.Data Error: 40 : BindingExpression path error: 'TitlesLookup' property not found on 'object' ''ContactViewModel_1b9cecb8_4129_4573_9da6_3c4548284e6c' (HashCode=3633470)'. BindingExpression:Path=TitlesLookup; DataItem='ContactViewModel_1b9cecb8_4129_4573_9da6_3c4548284e6c' (HashCode=3633470); target element is 'LookUpEdit' (Name=''); target property is 'UnderlyingObject' (type 'Object')
System.Windows.Data Error: 40 : BindingExpression path error: 'SocietyMembership' property not found on 'object' ''ContactViewModel_1b9cecb8_4129_4573_9da6_3c4548284e6c' (HashCode=3633470)'. BindingExpression:Path=SocietyMembership; DataItem='ContactViewModel_1b9cecb8_4129_4573_9da6_3c4548284e6c' (HashCode=3633470); target element is 'LookUpEdit' (Name=''); target property is 'UnderlyingObject' (type 'Object')

Put simply is this a fault in the scaffolding wizard or is there something that I should be edititing post view creation.

NB the application builds and runs, I'm just curios as to why lookup edits built with the scaffolding wizard seem to create these binding errors.

Many thanks

Dom

Comments (2)
DevExpress Support Team 8 years ago

    Hi Dom,

    In general, the Scafoolding Wizard should not cause such issues. Do you see these binding errors only in your working project or are they reproducible even in a brand-new application related to the same database? Would you please provide us with a small sample demonstrating this issue for further research?

    Thanks,
    Alex

      Hi Alex

      Thank you for getting back to me.  I have been doing a lot of research into this over the course of the weekend and have come to the conclusion that the root cause of this is probably connected with layout controls.  You are quite correct in saying that 'in general the scaffolding wizard should not create such issues', and indeed in initially (ie when they first run and one views the freshly built application they don't).

      My issue appears to step from post creation customisations.  As an example consider the xaml  below.  This is from a single object view model in which there was originally an overriding DataLayoutControl that contained fields for the individual colulmns in the underlying table at the top (including some lookup edits for foreign key relations) and then a number of tabs below that showing record collections from related tables directly related to that single object.  (I have also attached an image of the altered view to make the xaml easier to follow.

      The issue seems to be with the lookup edits which I suspect, with the addition on my part of further layout controls, are becoming 'detached' from their direct link to the underlying view model.

      This begs a couple of questions;

      1. is my assumption in your opinion correct?
      2. if so can you suggest what change I should make to the binding such that it returns to the direct relationship that it had with the underlying view model?   In essence when I added the new layout controls I simply moved the original xaml describing the lookup edits into the sections where I wanted them to appear ( thus demonstrating I don't doubt a fundamental lack of understanding of xaml data banding in the process!!).

      Lastly if I am indeed correct might I suggest an additional help in the section of the documentation where you describe customisations that can be made to scaffold generated applications that shows both how such items can become 'detached' from the underlying viewModel and the syntax needed to correct the detachment.

      NB when you view the image the lookup edits affected are all those with drop downs.  In most cases I changed them to only show a few columns but the main data binding remains as described by the scaffolding wizard.

      XAML
      <UserControl x:Class="VtlFishTracker.Views.VesselView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars" xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon" xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol" xmlns:dxdo="http://schemas.devexpress.com/winfx/2008/xaml/docking" xmlns:dxrudex="http://schemas.devexpress.com/winfx/2008/xaml/reports/userdesignerextensions" xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" xmlns:viewModel="clr-namespace:VtlFishTracker.ViewModels" xmlns:view="clr-namespace:VtlFishTracker.Views" xmlns:localization="clr-namespace:VtlFishTracker.Localization" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="800" d:DesignWidth="600" DataContext="{dxmvvm:ViewModelSource viewModel:VesselViewModel}"> <UserControl.Resources> <ResourceDictionary Source="../../Resources/EntityViewResources.xaml" /> </UserControl.Resources> <DockPanel Style="{StaticResource EntityView.RootContainer}"> <dxr:RibbonControl DockPanel.Dock="Top" Style="{StaticResource EntityView.RibbonControl}"> <dxr:RibbonDefaultPageCategory> <dxr:RibbonPage Style="{StaticResource EntityView.RibbonPage}"> <dxr:RibbonPageGroup Style="{StaticResource EntityView.RibbonPageGroup.Main}"> <dxb:BarButtonItem Style="{StaticResource EntityView.Command.Save}" /> <dxb:BarButtonItem Style="{StaticResource EntityView.Command.SaveAndClose}" /> <dxb:BarButtonItem Style="{StaticResource EntityView.Command.SaveAndNew}" /> <dxb:BarButtonItem Style="{StaticResource EntityView.Command.Reset}" /> <dxb:BarButtonItem Style="{StaticResource EntityView.Command.Delete}" /> <dxb:BarButtonItem Style="{StaticResource EntityView.Command.Close}" /> </dxr:RibbonPageGroup> <dxr:RibbonPageGroup Style="{StaticResource EntityView.RibbonPageGroup.Layout}"> <dxb:BarCheckItem IsChecked="{Binding IsCustomization, ElementName=layoutControl}" Style="{StaticResource EntityView.Command.Customize}" /> <dxb:BarButtonItem Style="{StaticResource EntityView.Command.SaveLayout}" /> <dxb:BarButtonItem Style="{StaticResource EntityView.Command.ResetLayout}" /> </dxr:RibbonPageGroup> </dxr:RibbonPage> </dxr:RibbonDefaultPageCategory> </dxr:RibbonControl> <dxr:RibbonStatusBarControl DockPanel.Dock="Bottom" Style="{StaticResource EntityView.RibbonStatusBar}" /> <dxlc:DataLayoutControl x:Name="layoutControl" AutoGenerateItems="False" Style="{StaticResource EntityView.DataLayoutControl}"> <dxlc:LayoutGroup TabStyle="{DynamicResource TabStyleBlue}" View="Tabs"> <dxlc:LayoutGroup Header="Main Details" Orientation="Vertical"> <dxlc:LayoutGroup Margin="4" GroupBoxStyle="{StaticResource GroupBoxStyleBlue}" Header="Vessel" Orientation="Vertical" View="GroupBox"> <dxlc:DataLayoutItem x:Name="layoutItemVesselName" Binding="{Binding VesselName, UpdateSourceTrigger=PropertyChanged}"> <dxmvvm:Interaction.Behaviors> <dxmvvm:FocusBehavior FocusDelay="0:0:0.2" /> </dxmvvm:Interaction.Behaviors> </dxlc:DataLayoutItem> <dxlc:DataLayoutItem x:Name="layoutItemVesselPln" Binding="{Binding VesselPln, UpdateSourceTrigger=PropertyChanged}"> <dxe:TextEdit CharacterCasing="Upper" EditValue="{Binding VesselPln, Mode=OneWay}" /> </dxlc:DataLayoutItem> <dxlc:DataLayoutItem x:Name="layoutItemContact" Binding="{Binding OwnerId, Mode=OneTime}" Label="Vessel Owner"> <dxg:LookUpEdit DataContext="{Binding ElementName=layoutControl, Path=DataContext}" DisplayMember="ContactName" EditValue="{Binding Entity.OwnerId, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnSourceUpdated=True}" ItemsSource="{Binding LookUpContacts.Entities}" Style="{StaticResource EntityView.LookUpEdit}" ValueMember="ContactId" AutoPopulateColumns="False"> <dxg:LookUpEdit.PopupContentTemplate> <ControlTemplate TargetType="ContentControl"> <dxg:GridControl x:Name="PART_GridControl" ShowBorder="False" ShowLoadingPanel="{Binding LookUpContacts.IsLoading}"> <dxg:GridControl.Columns> <dxg:GridColumn IsSmart="True" FieldName="ContactName" /> </dxg:GridControl.Columns> <dxg:GridControl.View> <dxg:TableView AutoWidth="True" /> </dxg:GridControl.View> </dxg:GridControl> </ControlTemplate> </dxg:LookUpEdit.PopupContentTemplate> </dxg:LookUpEdit> </dxlc:DataLayoutItem> </dxlc:LayoutGroup> <dxlc:LayoutGroup Margin="4" GroupBoxStyle="{StaticResource GroupBoxStyleBlue}" Header="Vessel Defaults" Orientation="Vertical" View="GroupBox"> <dxlc:DataLayoutItem x:Name="layoutItemPortsLookup" Binding="{Binding PortsLookup, Mode=OneTime}" Label="Default port of landing"> <dxg:LookUpEdit DataContext="{Binding ElementName=layoutControl, Path=DataContext}" DisplayMember="PortDescription" EditValue="{Binding Entity.DefaultPortOfLanding, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnSourceUpdated=True}" ItemsSource="{Binding LookUpPortsLookups.Entities}" Style="{StaticResource EntityView.LookUpEdit}" ValueMember="ErsPortCode" AutoPopulateColumns="False"> <dxg:LookUpEdit.PopupContentTemplate> <ControlTemplate TargetType="ContentControl"> <dxg:GridControl x:Name="PART_GridControl" ShowBorder="False" ShowLoadingPanel="{Binding LookUpPortsLookups.IsLoading}"> <dxg:GridControl.Columns> <dxg:GridColumn IsSmart="True" FieldName="UNCountryCode" /> <dxg:GridColumn IsSmart="True" FieldName="PortDescription" /> <dxg:GridColumn IsSmart="True" FieldName="PortCode" /> <dxg:GridColumn IsSmart="True" FieldName="ErsPortCode" /> </dxg:GridControl.Columns> <dxg:GridControl.View> <dxg:TableView AutoWidth="True" /> </dxg:GridControl.View> </dxg:GridControl> </ControlTemplate> </dxg:LookUpEdit.PopupContentTemplate> </dxg:LookUpEdit> </dxlc:DataLayoutItem> <dxlc:DataLayoutItem x:Name="layoutItemFishingAreasLookup" Binding="{Binding FishingAreasLookup, Mode=OneTime}" Label="Default Fishing Area"> <dxg:LookUpEdit DataContext="{Binding ElementName=layoutControl, Path=DataContext}" DisplayMember="FishingAreaDescription" EditValue="{Binding Entity.DefaultFishingArea, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnSourceUpdated=True}" ItemsSource="{Binding LookUpFishingAreasLookups.Entities}" Style="{StaticResource EntityView.LookUpEdit}" ValueMember="FishingAreaCode"> <dxg:LookUpEdit.PopupContentTemplate> <ControlTemplate TargetType="ContentControl"> <dxg:GridControl x:Name="PART_GridControl" ShowBorder="False" ShowLoadingPanel="{Binding LookUpFishingAreasLookups.IsLoading}" /> </ControlTemplate> </dxg:LookUpEdit.PopupContentTemplate> </dxg:LookUpEdit> </dxlc:DataLayoutItem> <dxlc:DataLayoutItem x:Name="layoutItemFishingZonesLookup" Binding="{Binding FishingZonesLookup, Mode=OneTime}" Label="Default Ices Zone"> <dxg:LookUpEdit DataContext="{Binding ElementName=layoutControl, Path=DataContext}" DisplayMember="IcesDescription" EditValue="{Binding Entity.DefaultIcesZone, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnSourceUpdated=True}" ItemsSource="{Binding LookUpFishingZonesLookups.Entities}" Style="{StaticResource EntityView.LookUpEdit}" ValueMember="IcesZoneCode" AutoPopulateColumns="False"> <dxg:LookUpEdit.PopupContentTemplate> <ControlTemplate TargetType="ContentControl"> <dxg:GridControl x:Name="PART_GridControl" ShowBorder="False" ShowLoadingPanel="{Binding LookUpFishingZonesLookups.IsLoading}"> <dxg:GridControl.Columns> <dxg:GridColumn IsSmart="True" FieldName="IcesZoneCode" /> <dxg:GridColumn IsSmart="True" FieldName="IcesDescription" /> </dxg:GridControl.Columns> <dxg:GridControl.View> <dxg:TableView AutoWidth="True" /> </dxg:GridControl.View> </dxg:GridControl> </ControlTemplate> </dxg:LookUpEdit.PopupContentTemplate> </dxg:LookUpEdit> </dxlc:DataLayoutItem> <dxlc:DataLayoutItem x:Name="layoutItemCatchesMscFish" Binding="{Binding CatchesMscFish, UpdateSourceTrigger=PropertyChanged}" /> <dxlc:DataLayoutItem x:Name="layoutItemVesselActive" Binding="{Binding VesselActive, UpdateSourceTrigger=PropertyChanged}" /> </dxlc:LayoutGroup> <dxlc:LayoutGroup Margin="4" GroupBoxStyle="{StaticResource GroupBoxStyleBlue}" Header="Vessel Finances" Orientation="Vertical" View="GroupBox"> <dxlc:DataLayoutItem x:Name="layoutItemDeduction" Binding="{Binding DeductionId, Mode=OneTime}" Label="Deduction Type"> <dxg:LookUpEdit DataContext="{Binding ElementName=layoutControl, Path=DataContext}" DisplayMember="DeductionType" EditValue="{Binding Entity.DeductionId, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnSourceUpdated=True}" ItemsSource="{Binding LookUpDeductions.Entities}" Style="{StaticResource EntityView.LookUpEdit}" ValueMember="DeductionId" AutoPopulateColumns="False"> <dxg:LookUpEdit.PopupContentTemplate> <ControlTemplate TargetType="ContentControl"> <dxg:GridControl x:Name="PART_GridControl" ShowBorder="False" ShowLoadingPanel="{Binding LookUpDeductions.IsLoading}"> <dxg:GridControl.Columns> <dxg:GridColumn IsSmart="True" FieldName="DeductionId" /> <dxg:GridColumn IsSmart="True" FieldName="DeductionType" /> <dxg:GridColumn IsSmart="True" FieldName="DeductionRate"> <dxg:GridColumn.EditSettings> <dxe:TextEditSettings MaskType="Numeric" Mask="p2" MaskUseAsDisplayFormat="True" /> </dxg:GridColumn.EditSettings> </dxg:GridColumn> </dxg:GridControl.Columns> <dxg:GridControl.View> <dxg:TableView AutoWidth="True" /> </dxg:GridControl.View> </dxg:GridControl> </ControlTemplate> </dxg:LookUpEdit.PopupContentTemplate> </dxg:LookUpEdit> </dxlc:DataLayoutItem> <dxlc:DataLayoutItem x:Name="layoutItemInternalCommission" Binding="{Binding InternalCommission, UpdateSourceTrigger=PropertyChanged}"> <dxe:TextEdit EditValue="{Binding InternalCommission, Mode=OneWay}" Mask="P2" MaskType="Numeric" MaskUseAsDisplayFormat="True" /> </dxlc:DataLayoutItem> <dxlc:DataLayoutItem x:Name="layoutItemInternalDeduction" Binding="{Binding InternalDeduction, UpdateSourceTrigger=PropertyChanged}"> <dxe:TextEdit EditValue="{Binding InternalDeduction, Mode=OneWay}" Mask="p2" MaskType="Numeric" MaskUseAsDisplayFormat="True" /> </dxlc:DataLayoutItem> </dxlc:LayoutGroup> </dxlc:LayoutGroup> <!-- Related Tables section NB the original data layout control is terminated below the following section -->

      Dom

      Answers approved by DevExpress Support

      created 8 years ago

      Hi Dom,
      Thank you for the provided XAML. It helped me to determine the issue.
      The problem is more related to DataLayoutControl specifics than to the Scaffolding Wizard. DataLayoutItem assigns the DataLayoutItem.UnderlyingObject attached property to its child (LookUpEdit in your case). The property value is resolved by a binding that inherits its Path from the DataLayoutItem.Binding property, but operates the child's DataContext, which is reassigned to another object in your XAML. As a result, a binding exception is thrown.

      If your task implies binding an editor to an object outside DataLayoutItem (and thus, you don't need the DataLayoutItem functionality in this particular case), replace the item with LayoutItem.

      XAML
      <dxlc:DataLayoutControl x:Name="layoutControl"> <dxlc:LayoutGroup Orientation="Vertical" View="GroupBox"> <dxlc:LayoutItem Label="Default port of landing"> <dxg:LookUpEdit DataContext="{Binding ElementName=layoutControl, Path=DataContext}" EditValue="..." /> </dxlc:LayoutItem> ... </dxlc:LayoutGroup> </dxlc:DataLayoutControl>

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.