Question Binding DataGidComboBoxColumn to parent information

Sep 8, 2008 at 2:12 PM
Originally posted on the MSDN forums, but they brought me over here, so here's my question:

I have an xml where attributes can reference previously defined properties.  For example, the following is a valid snippet:
<Property name="DataPoint1" /> 
<Property name="DataPoint2" /> 
<Property name="DataPoint3" /> 
<Property name="DataPoint4" /> 
<Property name="DataPoint5" /> 
<Event> 
    <Parameter ref="DataPoint1" /> 
    <Parameter ref="DataPoint2" /> 
    <Parameter ref="DataPoint4" /> 
    <Parameter ref="DataPoint5" /> 
</Event> 

I want to set up a ComboBoxColumn in a datagrid that will query the current data context for valid properties.  This would be perfect (if it were possible):

<tool:DataGrid x:Name="dgParameters" AutoGenerateColumns="False"
    <tool:DataGrid.Columns> 
        <tool:DataGridTemplateColumn> 
            <tool:DataGridTemplateColumn.CellTemplate> 
                <DataTemplate> 
                    <CheckBox x:Name="chkSelected" /> 
                </DataTemplate> 
            </tool:DataGridTemplateColumn.CellTemplate> 
        </tool:DataGridTemplateColumn> 
        <tool:DataGridComboBoxColumn x:Name="dgcReferences" Header="Reference" DataFieldBinding="{Binding XPath=@ref}"  
              ItemsSource="{Binding XPath=../../Property/@name}"/> 
    </tool:DataGrid.Columns> 
</tool:DataGrid> 

This is invalid because of the following error:

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element.

In addition, even if that worked, I'm pretty sure the combo box would only be bound once, and this datagrid may be reused to display different sets of xml.