Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
RelativeSource FindAncestor Binding from XamEditor Controls to CellValuePresenter doesn't Work with Default Namespace?
posted

Hi,

In a XamDataGrid (v13.2) control I store my field view model object containing formatting info for the field in Field.Label (object) property. Then I use relative source findancestor mode binding to format the dataitem inside each CellValuePresenter.

For instance, for a numeric column where I have XamNumericEditor inside the CellValuePresenter I set the Format property to bind to its ancestor of type CellValuePresenter, using the path Field.Label.ValueFormat (a string property containing numeric formatting info). Like so:

<Style TargetType="{x:Type Editors:XamNumericEditor}">
   <Setter Property="Format" Value ="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataPresenter:CellValuePresenter}, Path=Field.Label.ValueFormat}" />
</Style>

The binding expression did work, but it broke when I changed DataPresenter namespace uri

from (worked):

xmlns:DataPresenter="clr-namespace:Infragistics.Windows.DataPresenter;assembly=InfragisticsWPF4.DataPresenter.v13.2" 

to any of these (none worked):

xmlns:DataPresenter="http://infragistics.com/DataPresenter"

xmlns:DataPresenter="http://schemas.infragistics.com/xaml/wpf"

xmlns:DataPresenter="http://infragistics.com/Windows"

Here's the output when I set the binding TraceLevel to High with xmlns:DataPresenter="http://infragistics.com/DataPresenter":

System.Windows.Data Warning: 54 : Created BindingExpression (hash=25807577) for Binding (hash=17780589)
System.Windows.Data Warning: 56 : Path: 'Field.Label.ValueFormat'
System.Windows.Data Warning: 58 : BindingExpression (hash=25807577): Default mode resolved to OneWay
System.Windows.Data Warning: 59 : BindingExpression (hash=25807577): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 60 : BindingExpression (hash=25807577): Attach to Infragistics.Windows.Editors.XamNumericEditor.Format (hash=30941604)
System.Windows.Data Warning: 64 : BindingExpression (hash=25807577): RelativeSource (FindAncestor) requires tree context
System.Windows.Data Warning: 63 : BindingExpression (hash=25807577): Resolve source deferred

System.Windows.Data Warning: 65 : BindingExpression (hash=25807577): Resolving source
System.Windows.Data Warning: 68 : BindingExpression (hash=25807577): Found data context element: <null> (OK)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried ContentPresenter (hash=18763302)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried CardPanel (hash=34651994)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried CellValuePresenter (hash=43432495) <-- SHOULD'VE STOPPED HERE!
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried CellPlaceholder (hash=55348143)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried StackPanel (hash=28371241)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried ContentPresenter (hash=54014584)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried CardPanel (hash=16369212)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried DataRecordCellArea (hash=13105182)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried ContentPresenter (hash=50837775)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried Grid (hash=66800497)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried CardPanel (hash=27336841)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried DataRecordPresenter (hash=54886792)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried XamDataGrid (hash=39801087)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried Grid (hash=24219082)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried ContentPresenter (hash=16645150)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried Border (hash=15588630)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried RvApiReportView (hash=6079946)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried ContentPresenter (hash=54719514)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried Grid (hash=22713585)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried Border (hash=3095679)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried Grid (hash=27861117)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried CustomContentPane (hash=40761713)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried SplitPane (hash=13364467)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried ContentPresenter (hash=49423469)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried Grid (hash=42158038)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried Grid (hash=43878027)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried Border (hash=59357923)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried Grid (hash=64459265)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried AdornerDecorator (hash=43262477)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried CustomPaneToolWindow (hash=40096741)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried ContentPresenter (hash=53817976)
System.Windows.Data Warning: 71 : Lookup ancestor of type CellValuePresenter: queried ToolWindowHostWindow (hash=14599739)

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Infragistics.Windows.DataPresenter.CellValuePresenter', AncestorLevel='1''. BindingExpression:Path=Field.Label.ValueFormat; DataItem=null; target element is 'XamNumericEditor' (Name=''); target property is 'Format' (type 'String')

What could be the reason?