将所选行数据网格的值传递给弹出框

时间:2017-09-20 08:56:34

标签: c# wpf data-binding wpfdatagrid

我有一个弹出框,显示在每一行上,当我点击该弹出窗口时,它应该显示所选行的更多细节。我能够获取所选行的值,但我无法将它们绑定到弹出框控件。

<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>

1 个答案:

答案 0 :(得分:1)

应该不是

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

而不是

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