In my XamDataGrid I have an unboundField with multiBinding one item comes from the collection XamDataGrid is binded into, and the other "SelectedPipeMode" comes from a property in the viewmodel. which means it has a different dataContext than the collection
<igWPF:UnboundField Label="Pipe Output Width/Height" Width="auto">
<igWPF:UnboundField.Binding>
<MultiBinding Converter="{StaticResource settingsOutputResToStringConverter}" >
<Binding Path="Key"/>
<Binding Path="SelectedPipeMode" RelativeSource="{RelativeSource AncestorType=sensorResolutionTables:SensorResolutionsTablesUserControl}"/>
</MultiBinding>
</igWPF:UnboundField.Binding>
<igWPF:UnboundField.Settings>
<igWPF:FieldSettings AllowEdit="False" SortComparer="{StaticResource customFilterComparer}" >
</igWPF:FieldSettings>
</igWPF:UnboundField.Settings>
</igWPF:UnboundField>
I want to convert my XamdataGrid into a userControl since I'm going to reuse it.
this is how I use my new user control:
<sensorResolutionTables:SensorResolutionsTablesUserControl Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="6" DataContext="{Binding SensorResolutionTablesViewModel}"/>
Can you see my mistake?
Here is my error:
System.Windows.Data Warning: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='SkyCamWorkFlow.SensorResolutionTables.SensorResolutionsTablesUserControl', AncestorLevel='1''. BindingExpression:Path=SelectedPipeMode; DataItem=null; target element is 'ValueHolderWithDataContext' (HashCode=1650399); target property is 'Value' (type 'Object')
Sorry to provide an answer so late, but I just faced the same issue and maybe it might be useful to others as well.
First, it is not YOUR mistake, is more about the grid binding definition which is kind of weird sometime, IMO.
Your binding will work if placed inside of a CellValuePresenter Template by using a static resource.
<Style x:Key="PipeOutputPresenterStyle" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource settingsOutputResToStringConverter}" >
<Binding Path="DataItem.Key"/>
<Binding Path="SelectedPipeMode" RelativeSource="{RelativeSource AncestorType=sensorResolutionTables:SensorResolutionsTablesUserControl}"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Pay attention to one of your original MultiBinding Path that have been updated with DataItem. prefix !
Then your XamDataGrid UnboundField binding should look like :
<igWPF:UnboundField Label="Pipe Output Width/Height" Width="auto">
<igWPF:UnboundField.Settings>
<igWPF:FieldSettings
CellValuePresenterStyle="{StaticResource PipeOutputPresenterStyle}"
AllowEdit="False" SortComparer="{StaticResource customFilterComparer}" />
</igWPF:UnboundField.Settings>
</igWPF:UnboundField>
HTH