Search code examples
c#wpfdata-bindingwpfdatagrid

Pass value of selected row of datagrid to popup box


I have a popupbox which is shown on every row and when I click on that popup it should show the more details of the selected row. I was able to get values of selected row but I am unable to bind them to popupbox controls.

<DataGrid x:Name="CRDataGrid" AutoGenerateColumns="False" SelectionMode="Single" SelectedItem="{Binding SelectedCR}" FontSize="14" CanUserAddRows="False" ItemsSource="{Binding crentities}"
CanUserDeleteRows="False" md:DataGridAssist.ColumnHeaderPadding="4" md:DataGridAssist.CellPadding="4" SelectionUnit="FullRow" MouseDoubleClick="DataGrid_MouseDoubleClick" RowDetailsVisibilityMode="VisibleWhenSelected" HeadersVisibility="All" Grid.ColumnSpan="2"  Grid.Row="1" Margin="20" >
    <DataGrid.Columns>
        <DataGridTextColumn Header="Title" IsReadOnly="True" Binding="{Binding LogName}" Width="80"   />
        <DataGridTextColumn Header="MUIdentifier" IsReadOnly="True" Binding="{Binding MU_Identifier}" Width="100"  />
        <DataGridTextColumn Header="Status" IsReadOnly="True" Binding="{Binding Status}" Width="80" />
        <DataGridTextColumn Header="RequestType" IsReadOnly="True"  Binding="{Binding RequestType}" Width="100" />
        <DataGridTextColumn Header="DateTime" IsReadOnly="True" Binding="{Binding Create_Date,TargetNullValue='-'}"  Width="100" />
        <DataGridTextColumn Header="SoftwareVersion" IsReadOnly="True" Binding="{Binding SW_Version}" Width="200"  />
        <DataGridTemplateColumn >
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <md:PopupBox DockPanel.Dock="Right" PlacementMode="BottomAndAlignRightEdges" StaysOpen="True">
                        <md:PopupBox.ToggleContent>
                            <md:PackIcon Kind="DotsHorizontal" Margin="4 0 4 0" Width="24" Height="24"
                                Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=md:PopupBox}, Path=Foreground}" />
                        </md:PopupBox.ToggleContent>
                        <TextBox Grid.Column="1" Grid.Row="1" Text="{Binding ElementName=CRDataGrid, Path= SelectedCR.MU_Identifier}" />
                    </md:PopupBox>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

Solution

  • Shouldn't

    <TextBox Grid.Column="1" Grid.Row="1" Text="{Binding ElementName=CRDataGrid, Path= SelectedCR.MU_Identifier}" />
    

    instead be

    <TextBox Grid.Column="1" Grid.Row="1" Text="{Binding ElementName=CRDataGrid, Path= SelectedItem.MU_Identifier}" />
    

    ?