QA@IT
«回答へ戻る

回答を投稿

それであれば、こうか、

<DataGrid x:Name="A" AutoGenerateColumns="True" >

  <DataGrid.ColumnHeaderStyle>
    <Style TargetType="DataGridColumnHeader">
      <Setter Property="HorizontalContentAlignment" Value="Center"/>
    </Style>
  </DataGrid.ColumnHeaderStyle>

  <DataGrid.CellStyle>
    <Style TargetType="DataGridCell">
      <Style.Setters>
        <Setter Property="TextBlock.TextAlignment" Value="Center" />
      </Style.Setters>
    </Style>
  </DataGrid.CellStyle>

</DataGrid>

こうですね。

<DataGrid x:Name="A" AutoGenerateColumns="False" >

  <DataGrid.Columns>
    <DataGridTextColumn Header="月" Binding="{Binding 月}" Width="10"></DataGridTextColumn>
    <DataGridTextColumn Header="目標" Binding="{Binding 目標}" Width="100"></DataGridTextColumn>
    <DataGridTextColumn Header="実績" Binding="{Binding 実績}" Width="100"></DataGridTextColumn>
    <DataGridTextColumn Header="差額" Binding="{Binding 差額}" Width="50"></DataGridTextColumn>

    <DataGridTextColumn Header="差額累計" Binding="{Binding 差額累計}" Width="100">

      <DataGridTextColumn.ElementStyle>
        <Style TargetType="{x:Type TextBlock}" >
          <Setter Property="TextAlignment" Value="Center" />
        </Style>
      </DataGridTextColumn.ElementStyle>

    </DataGridTextColumn>

  </DataGrid.Columns>


  <DataGrid.ColumnHeaderStyle>
    <Style TargetType="DataGridColumnHeader">
      <Setter Property="HorizontalContentAlignment" Value="Center"/>
    </Style>
  </DataGrid.ColumnHeaderStyle>

</DataGrid>
それであれば、こうか、

```xml
<DataGrid x:Name="A" AutoGenerateColumns="True" >

  <DataGrid.ColumnHeaderStyle>
    <Style TargetType="DataGridColumnHeader">
      <Setter Property="HorizontalContentAlignment" Value="Center"/>
    </Style>
  </DataGrid.ColumnHeaderStyle>

  <DataGrid.CellStyle>
    <Style TargetType="DataGridCell">
      <Style.Setters>
        <Setter Property="TextBlock.TextAlignment" Value="Center" />
      </Style.Setters>
    </Style>
  </DataGrid.CellStyle>
  
</DataGrid>
```

こうですね。

```xml
<DataGrid x:Name="A" AutoGenerateColumns="False" >

  <DataGrid.Columns>
    <DataGridTextColumn Header="月" Binding="{Binding 月}" Width="10"></DataGridTextColumn>
    <DataGridTextColumn Header="目標" Binding="{Binding 目標}" Width="100"></DataGridTextColumn>
    <DataGridTextColumn Header="実績" Binding="{Binding 実績}" Width="100"></DataGridTextColumn>
    <DataGridTextColumn Header="差額" Binding="{Binding 差額}" Width="50"></DataGridTextColumn>
    
    <DataGridTextColumn Header="差額累計" Binding="{Binding 差額累計}" Width="100">

      <DataGridTextColumn.ElementStyle>
        <Style TargetType="{x:Type TextBlock}" >
          <Setter Property="TextAlignment" Value="Center" />
        </Style>
      </DataGridTextColumn.ElementStyle>

    </DataGridTextColumn>
    
  </DataGrid.Columns>


  <DataGrid.ColumnHeaderStyle>
    <Style TargetType="DataGridColumnHeader">
      <Setter Property="HorizontalContentAlignment" Value="Center"/>
    </Style>
  </DataGrid.ColumnHeaderStyle>

</DataGrid>
```