0

この行をコードで使用しましたが、行オブジェクトが表示されず、行がnullになります。

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

Datagrid 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 に答える