1

我正在使用选项卡控件,并且我的选项卡控件中有两个选项卡,然后每个选项卡中有一个数据网格。但是,现在我可以在第一个数据网格中选择行,但不能在第二个中选择行。我不知道为什么我不能选择第二个数据网格中的行。

下面是我的xaml:

<TabControl Height="547" HorizontalAlignment="Left" Margin="12,14,0,0" Name="ManageTab" VerticalAlignment="Top" Width="768" Grid.RowSpan="2" 
                    SelectionChanged="ManageTab_SelectionChanged">
            <TabItem Header="STUT" Name="tab1">
                <Grid Height="520" Width="765" DataContext="{StaticResource UserViewSource}">
                    <DataGrid AutoGenerateColumns="False" EnableRowVirtualization="True" Height="514" HorizontalAlignment="Left" 
                  ItemsSource="{Binding}" Name="UserDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected"
                  AlternatingRowBackground="LightBlue" VerticalContentAlignment="Center"
                  HorizontalGridLinesBrush="Gray" VerticalGridLinesBrush="Gray"
                  VerticalAlignment="Top" Width="346" SelectedCellsChanged="UserDataGrid_SelectedCellsChanged">
                        <DataGrid.Columns>
                            <DataGridTextColumn x:Name="AccColumn" Binding="{Binding Path=Acc}" Header="Account" Width="80" IsReadOnly="True" />
                            <DataGridTextColumn x:Name="NameColumn" Binding="{Binding Path=Name}" Header="Name" Width="80" IsReadOnly="True" />
                        </DataGrid.Columns>
                    </DataGrid>
                    <Button Content="Exit" Height="49" HorizontalAlignment="Left" Margin="669,0,0,110" Name="btnExit" VerticalAlignment="Bottom" Width="75" Click="btnExit_Click" />
                </Grid>
            </TabItem>
            <TabItem Header="CLASS" Name="tab2">
                <Grid Height="508" Width="753" DataContext="{StaticResource ClassViewSource}">
                    <DataGrid AutoGenerateColumns="False" EnableRowVirtualization="True" Height="514" HorizontalAlignment="Left" 
                                  ItemsSource="{Binding}" Margin="6,2,0,0" Name="ClassDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected"
                                  AlternatingRowBackground="LightBlue" VerticalContentAlignment="Center"
                                  HorizontalGridLinesBrush="Gray" VerticalGridLinesBrush="Gray"
                                  VerticalAlignment="Top" Width="342" SelectedCellsChanged="ClassDataGrid_SelectedCellsChanged">
                        <DataGrid.Columns>
                            <DataGridTextColumn x:Name="ClassNameColumn" Binding="{Binding Path=ClassName}" Header="ClassName" Width="280" />
                        </DataGrid.Columns>
                    </DataGrid>
                    <Button Content="Exit" Height="49" HorizontalAlignment="Left" Margin="672,0,0,178" Name="btnExit2" VerticalAlignment="Bottom" Width="75" Click="btnExit_Click"/>
                </Grid>
            </TabItem>
        </TabControl>
4

1 回答 1

2

最后,我发现我把我UserViewSource = ((CollectionViewSource)(this.FindResource("UserViewSource")));的 in cs 文件放到了 Window_Loaded 函数中。然后,它起作用了。原来,我把它放到Tab_selectionchanged函数里面。

于 2013-04-29T10:24:51.853 回答