将第二个datagrid绑定到第一个datagrid的selecteditem

时间:2017-04-11 08:35:10

标签: c# wpf datagrid

我有一个数据网格。单击行时,将显示rowdetails。这很好。

在rowdetails中有一个复选框&如果用户单击此按钮,则会显示另一个数据网格,这也是有效的。

问题是,当这个额外的数据网格出现时,有列标题,但你无法输入数据,没有行输入数据,为什么?

XAML代码(为了简短起见,省略了一些代码)

 <DataGrid Grid.Row="1"
                          ItemsSource="{Binding HldLogEQCurr, UpdateSourceTrigger=PropertyChanged}"
                          SelectedItem="{Binding SelectedHldLogEq, UpdateSourceTrigger=PropertyChanged}"
                          Style="{StaticResource DataGridTemplate1}"
                          ColumnHeaderStyle="{StaticResource DG_ColumnHeaderCenter1}"                                            
                          RowStyle="{StaticResource DG_Row1}"
                          CellStyle="{StaticResource DG_Cell1}"                                    
                          RowHeaderStyle="{StaticResource DG_RowHeader1}"                              
                          AutoGenerateColumns="False"
                          HorizontalAlignment="Stretch"                           
                          Background="Silver" 
                          Margin="50,50,50,50"                              
                          CanUserDeleteRows="False"
                          CanUserAddRows="False"
                          RowHeaderWidth="30">

                        <DataGrid.RowDetailsTemplate>
                            <DataTemplate>
                                <Grid x:Name="RowDetailGrid"            
                                      Margin="5"
                                      HorizontalAlignment="Left">


                                            <DataGrid Grid.Row="2"
                                              ItemsSource="{Binding SelectedItem.NewSecurityList,  UpdateSourceTrigger=PropertyChanged}"                                                                  
                                              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,0"
                                              Visibility="{Binding IsChecked, ElementName=chkParent, Converter={StaticResource BoolToVis}}"
                                              AutoGenerateColumns="False">
                                                <DataGrid.Columns>
                                                    <DataGridTextColumn Header="ISIN" Binding="{Binding ISIN, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="False" MinWidth="75"/>
                                                    <DataGridTextColumn Header="Sedol" Binding="{Binding Sedol, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="False" MinWidth="75"/>
                                                    <DataGridTextColumn Header="Ticker" Binding="{Binding Ticker, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="False" MinWidth="75"/>
                                                    <DataGridTextColumn Header="Name" Binding="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="False" MinWidth="200"/>
                                                    <DataGridTextColumn Header="FX" Binding="{Binding FX, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="False" MinWidth="75"/>
                                                </DataGrid.Columns>
                                            </DataGrid>

                                        </Grid>
                                    </Border>
                                </Grid>
                            </DataTemplate>
                        </DataGrid.RowDetailsTemplate>

0 个答案:

没有答案