0

我在代码中使用了这一行,但它没有给出行对象,行为空。

DataGridRow row = 
   (DataGridRow)dtgSensorReadingList.ItemContainerGenerator.ContainerFromItem(channelGrid.Items[i]); 

数据网格 Xaml 代码:

<DataGrid Visibility="Hidden" VirtualizingStackPanel.VirtualizationMode="Standard" 
    CanUserAddRows="False" ColumnHeaderHeight="32" MinColumnWidth="65" 
    HorizontalGridLinesBrush="DarkKhaki" VerticalGridLinesBrush="DarkKhaki" 
    BorderBrush="DarkKhaki" Block.TextAlignment="Center" AutoGenerateColumns="True" 
    CanUserResizeColumns="False" CanUserReorderColumns="False" HorizontalAlignment="Left" 
    Margin="63,540,0,0" Name="dtgSensorReadingList" ItemsSource="{Binding}" Grid.Row="1" 
    Height="Auto" VerticalAlignment="Top" MaxWidth="1920" Width="Auto">
    <DataGrid.Resources>
        <Style TargetType="{x:Type DataGridColumnHeader}">
            <Setter Property="Background" Value="SteelBlue" />
            <Setter Property="Foreground" Value="white" />
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
        </Style>
        <Style TargetType="{x:Type DataGridRowHeader}">
            <Setter Property="Background" Value="Transparent" />
        </Style>
        <Style x:Key="Body_Content_DataGrid_Centering" TargetType="{x:Type DataGridCell}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DataGridCell}">
                        <Grid Background="{TemplateBinding Background}">
                            <ContentPresenter VerticalAlignment="Center" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </DataGrid.Resources>
</DataGrid> 

请让我知道如何获得 DatGridRow ?

4

1 回答 1

0

如果您想要选定的行,您可以绑定到数据网格中的 SelectedItem。

请告诉我们您想要实现的目标。

于 2012-06-29T06:17:51.900 回答