2012-06-29 60 views
0

我在代碼中使用了這一行,但它沒有給出行對象,行是空的。在WPF中獲取datagrid的datagridrow

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?

回答

0

如果您希望選定的行可以綁定到您的數據網格中的SelectedItem。

請告訴我們你想達到什麼目的。

+0

問題我會解決謝謝,我用數據網格的Updatelayout方法 – dhiraj

相關問題