0
Answer

Using a DataGrid inside a WPF ComboBox

Pedro Navarro

Pedro Navarro

15y
8.6k
1
Hello:
    I'm working on a project which requires the use of a DataGrid table as an item in ComboBox.  It is needed so the users can have a full description of the choices they are about to make.  I have succeeded in adding the DataGrid, populated with data from an XML document, to the ComboBox.  When clicked, the ComboBox displays the table.  The problem I have is in how to "connect" the chosen item in the table to the popup in the ComboBox.

I have set the ComboBox as follows:

       <ComboBox IsSynchronizedWithCurrentItem="True" HorizontalAlignment="Right" Margin="0,0,-103.709,157" VerticalAlignment="Bottom" Width="212" Height="28" x:Name="dgInComboBox" Style="{DynamicResource ComboBoxStyle3}">
            <ComboBox.DataContext>
                <Binding Source="{StaticResource InventoryData}"/>
            </ComboBox.DataContext>
        </ComboBox>

The popup settings inside "ComboBoxStyle3":

                           <Popup Focusable="false" AllowsTransparency="true" IsOpen="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" x:Name="PART_Popup">
                                <Microsoft_Windows_Themes:SystemDropShadowChrome MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="Shdw" Color="Transparent">
                                    <Border x:Name="DropDownBorder" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1">
                                        <!--This is the DataGrid contained within the bottom combo box-->
                                        <!--<dg:DataGrid IsSynchronizedWithCurrentItem="True" x:Name="dgInComboBox" ItemsSource="{TemplateBinding ItemsSource}">-->
                                            <dg:DataGrid IsSynchronizedWithCurrentItem="True" x:Name="dgInComboBox" AutoGenerateColumns="False"
                                                         ItemsSource="{Binding Source={StaticResource InventoryData},XPath=/Inventory/Books/Book}">
                                            <dg:DataGrid.DataContext>
                                                <Binding Source="{StaticResource InventoryData}" />
                                            </dg:DataGrid.DataContext>
                                            <dg:DataGrid.Columns>
                                                <dg:DataGridTextColumn DataFieldBinding="{Binding XPath=Title}" Header="Title"/>
                                                <dg:DataGridTextColumn DataFieldBinding="{Binding XPath=Summary}" Header="Summary"/>
                                            </dg:DataGrid.Columns>
                                        </dg:DataGrid>
                                    </Border>
                                </Microsoft_Windows_Themes:SystemDropShadowChrome>
                            </Popup>




So what I need is to populate the popup with the first column of the table (if only I could make the popup work).

Thanks in advance,
Pedro

Next Recommended Forum