I have a DataGrid in which one of the columns is an int TypeID, but I render it as ComboBox and map the TypeID value to a string using a bound list of values (TypeList) that contain [TypeID, Name] mappings. This bound list is expressed in XAML as
<ComboBox SelectedValue="{Binding TypeID}"
DisplayMemberPath="Name"
SelectedValuePath="TypeID"
ItemsSource="{Binding Path=DataContext.Database.TypeList, RelativeSource={RelativeSource AncestorType={x:Type Window }}}" />
This works great.
But what I want to do is in another column render the Name mapped from the TypeID as a simple string using a Multi-type converter. In my XAML, and in the same data grid I have
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Width="20">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource TypeIDConverter}">
<Binding Path="TypeID" />
<Binding Path="DataContext.Database.TypeList, RelativeSource={RelativeSource AncestorType={x:Type Window }}" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
This doesn't work at all.
In the type converter I get DependencyProperty.UnsetValue
for the second parameter. From IMultiValueConverter always passes in DependencyProperty.UnsetValue for list I know that the WPF system can't find my binding.
This is also seen in the output windows of the application where I get this error:
System.Windows.Data Warning: 40 : BindingExpression path error: 'DataContext' property not found on 'object' ''DatabaseItem' (HashCode=35751240)'. BindingExpression:Path=DataContext.Database.TypeList, RelativeSource={RelativeSource AncestorType={x:Type Window }; DataItem='DatabaseItem' (HashCode=35751240); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
And this is where I get confused. I thought that my RelativeSource was finding the window root and then looking for the DataContext there. Instead this error is telling me that it is looking for the DataContext on the row item (DatabaseItem) of the DataGrid.
Why is the same Binding expression working and not working in the same DataGrid?
What do I need to do to fix this?