2012-05-09 33 views
0

データビューをDataGridにバインドして、最初の行をRowheaderとして表示しようとすると問題が発生します。WPF DataGridのRowheaderをデータビューにバインドするとき

マイデータグリッドは次のようになります。このコードで発生

<DataGrid DockPanel.Dock="Top" Margin="15,15" HorizontalAlignment="Left" Name="ReportDataGrid" CanUserSortColumns="False" CanUserResizeColumns="False" CanUserReorderColumns="False" AutoGenerateColumns="True" CanUserResizeRows="False" IsReadOnly="True" HorizontalScrollBarVisibility="Auto" HeadersVisibility="All" Visibility="{Binding Path=ShowReportDataGrid}" SelectionMode="Single" SelectionUnit="Cell" ClipboardCopyMode="IncludeHeader"> 
    <DataGrid.CellStyle> 
     <Style TargetType="DataGridCell"> 
      <Setter Property="Width" Value="48"></Setter> 
       </Style> 
        </DataGrid.CellStyle> 
         <DataGrid.ColumnHeaderStyle> 
          <Style TargetType="DataGridColumnHeader"> 
           <Setter Property="Background" Value="{StaticResource DataGrid_Style_Header}" /> 
           <Setter Property="Foreground" Value="White" /> 
           <Setter Property="Padding" Value="10,0,10,0"/> 
           <Setter Property="Width" Value="48"></Setter> 
          </Style> 
         </DataGrid.ColumnHeaderStyle> 
         <DataGrid.RowHeaderStyle> 
          <Style TargetType="DataGridRowHeader"> 
           <Setter Property="Background" Value="{StaticResource DataGrid_Style_Header}" /> 
           <Setter Property="Foreground" Value="White" /> 
           <Setter Property="Padding" Value="10,0,10,0"/> 
           <Setter Property="Width" Value="48"></Setter> 
          </Style> 
         </DataGrid.RowHeaderStyle> 
        </DataGrid> 

何がデータグリッドは、行ヘッダを挿入して、グリッドの残りの部分でデータビューからデータを置き、行ヘッダを空のままにされていることです。 rowheaderにデータビューの最初の列を取得する良い解決策は何でしょうか?

答えて

0

私はそうのように、代わりにスタイルの問題を解決することになった:

<DataGrid.CellStyle> 
    <Style TargetType="DataGridCell"> 
     <Setter Property="Width" Value="48"></Setter> 
      <Style.Triggers> 
       <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Column.DisplayIndex, Mode=OneWay}" Value="0"> 
        <Setter Property="Background" Value="{StaticResource DataGrid_Style_Header}" />   
        <Setter Property="Foreground" Value="White" /> 
        <Setter Property="Width" Value="60"></Setter> 
        </DataTrigger> 
       </Style.Triggers> 
      </Style> 
     </DataGrid.CellStyle> 
関連する問題