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
下列範例會使用觸發程式,在選取儲存格時變更
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>
下圖顯示輸出。
套用 以
Style
更新 中
DataGrid
所有儲存格的視覺外觀。 若要定義
Style
儲存格的 ,請指定
TargetType
的
DataGridCell
。
Style
可以套用至資料表、資料行或儲存格層級的儲存格。 若要將 套用
Style
至資料行中的所有儲存格,請設定
DataGridColumn.CellStyle
屬性。 這會優先于
DataGrid.CellStyle
屬性。 若要將 套用
Style
至個別儲存格,請
Style
直接在 上
DataGridCell
設定 屬性。 這會優先于套用至儲存格的所有其他樣式。