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

プロパティ値

Style

DataGrid のセルに適用されるスタイル。 登録済みの既定値は null です。 この値が何に影響されるかの詳細については、DependencyProperty のトピックを参照してください。

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

<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>

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

背景が緑色の選択されたセル

注釈

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

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

適用対象

こちらもご覧ください