Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将datagrid列绑定到selecteditem属性_C#_Wpf_Xaml_Datagrid - Fatal编程技术网

C# 将datagrid列绑定到selecteditem属性

C# 将datagrid列绑定到selecteditem属性,c#,wpf,xaml,datagrid,C#,Wpf,Xaml,Datagrid,我有一个datagrid,如果单击一行,将显示行详细信息。在“详细信息”行中是另一个名为dgRights的数据网格 因此dgRights绑定到SelectItem.Funds,其中Funds是一个自定义列表。dgRights显示了4列,其中3列绑定良好,但第四列没有绑定(在我的代码中,它被称为“Rights Sedol”) 我希望列权限Sedol绑定到selectedItem而不是selectedItem.Funds的属性,这可能吗 我尝试了下面的代码行,但运气不好 <DataGridTe

我有一个datagrid,如果单击一行,将显示行详细信息。在“详细信息”行中是另一个名为dgRights的数据网格

因此dgRights绑定到SelectItem.Funds,其中Funds是一个自定义列表。dgRights显示了4列,其中3列绑定良好,但第四列没有绑定(在我的代码中,它被称为“Rights Sedol”)

我希望列权限Sedol绑定到selectedItem而不是selectedItem.Funds的属性,这可能吗

我尝试了下面的代码行,但运气不好

<DataGridTextColumn Header="Rights Sedol" Binding="{Binding SelectedItem.NewSecurity.Sedol, RelativeSource={RelativeSource AncestorType=Window}}/>                                

我还尝试将datagrid的ItemSource从SelectedItem.Funds更改为SelectItem,并将其他3个工作列更改为Funds.Code等,但这根本没有显示datagrid中的任何数据。所以我不知道该怎么办

App.xaml-我的行详细信息数据模板

<DataTemplate x:Key="DG_RowDetailRGHTSHist">
        <Grid x:Name="RowDetailGrid"            
              Margin="5"
              HorizontalAlignment="Left">
            <Border HorizontalAlignment="Left"
                    VerticalAlignment="Top"
                    Height="250"
                    CornerRadius="5">
                <Border.Background>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                        <GradientStop Offset="0" Color="Transparent"/>
                        <GradientStop Offset="1" Color="Transparent"/>
                    </LinearGradientBrush>
                </Border.Background>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="4*"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="400"/>
                        <ColumnDefinition Width="200"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0"
                               Grid.Column="0"
                               Margin="5,5,5,5"
                               HorizontalAlignment="Left"
                               FontSize="12"
                               FontWeight="Bold"
                               Foreground="Black" 
                               Text="Fund Summary">
                    </TextBlock>
                    <DataGrid Grid.Row="1" Grid.Column="0"  Grid.ColumnSpan="2"
                              ItemsSource="{Binding SelectedItem.Funds,  RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"                                                                  
                              RowStyle="{StaticResource DG_Row}"  
                              ColumnHeaderStyle="{StaticResource DG_ColumnHeader}" 
                              RowHeaderStyle="{StaticResource DG_RowHeaderNested}"
                              CellStyle="{StaticResource DG_Cell}" 
                              Background="Silver"
                              HorizontalGridLinesBrush="LightGray"
                              VerticalGridLinesBrush="LightGray"
                              CanUserAddRows="False"
                              CanUserDeleteRows="False"
                              Margin="50,5,5,20"
                              AutoGenerateColumns="False">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Fund Code" Binding="{Binding Code}" IsReadOnly="True" MinWidth="75"/>
                            <DataGridTextColumn Header="Fund Code SS" Binding="{Binding CodeSS}" IsReadOnly="True" MinWidth="75"/>
                            <DataGridTextColumn Header="Rights Sedol" Binding="{Binding SelectedItem.NewSecurity.Sedol, RelativeSource={RelativeSource AncestorType=Window}}" IsReadOnly="True" MinWidth="75"/>                                
                            <DataGridTextColumn Header="Number of Rights" Binding="{Binding CurrentNominal, Mode=TwoWay, StringFormat={}{0:N0}}" IsReadOnly="True"/>
                        </DataGrid.Columns>
                    </DataGrid>
                </Grid>
            </Border>
        </Grid>
    </DataTemplate>

您想访问第二个数据网格,因此需要指定AncestorLevel=2

{RelativeSource AncestorType=DataGrid, AncestorLevel=2}}

试试:{RelativeSource AncestorType=DataGrid,AncestorLevel=2}}AncestorLevel=2部分告诉它转到第二个DataGrid。谢谢你的帮助!如果你把它作为一个答案贴出来,很高兴把它标记为正确的
{RelativeSource AncestorType=DataGrid, AncestorLevel=2}}