次の方法で共有


DataGrid.CellStyle プロパティ

定義

DataGrid内のすべてのセルに適用されるスタイルを取得または設定します。

public:
 property System::Windows::Style ^ CellStyle { System::Windows::Style ^ get(); void set(System::Windows::Style ^ value); };
public System.Windows.Style CellStyle { get; set; }
member this.CellStyle : System.Windows.Style with get, set
Public Property CellStyle As Style

プロパティ値

DataGrid内のセルに適用されるスタイル。 登録済みの既定値は null です。 値に与える影響の詳細については、 DependencyPropertyを参照してください。

次の例では、トリガーを使用して、セルが選択されたときにDataGridCellBackgroundの色を変更します。

<DataGrid Name="DG1" ItemsSource="{Binding}" SelectionUnit="Cell" >
    <DataGrid.CellStyle>
        <Style TargetType="DataGridCell" >
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="SeaGreen"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </DataGrid.CellStyle>
</DataGrid>

次の図は、出力を示しています。

緑の背景を持つ選択したセル

注釈

Styleを適用して、DataGrid内のすべてのセルの外観を更新します。 セルのStyleを定義するには、DataGridCellTargetTypeを指定します。

Styleは、テーブル、列、またはセル レベルのセルに適用できます。 列内のすべてのセルに Style を適用するには、 DataGridColumn.CellStyle プロパティを設定します。 これは、 DataGrid.CellStyle プロパティよりも優先されます。 個々のセルにStyleを適用するには、DataGridCellに直接Styleプロパティを設定します。 これは、セルに適用される他のすべてのスタイルよりも優先されます。

適用対象

こちらもご覧ください