我想編輯WPF中的DataGrid
的單元格樣式。因此,使用Expression Blend中我的權利去 - 對象和時間線>>的DataGrid >>編輯其他模板>>編輯CellStyle >>編輯複製
這裏是出現在頁面上的什麼什麼:正確的方式來覆蓋WPF中的樣式值
<SolidColorBrush x:Key="{x:Static DataGrid.FocusBorderBrushKey}" Color="#FF000000"/>
<Style x:Key="DataGridCellStyle1" TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static DataGrid.FocusBorderBrushKey}}"/>
</Trigger>
</Style.Triggers>
</Style>
但我只想要改變填充和背景。相反,它給了我25行代碼,包括單元格模板!我是否錯過了一些東西,有沒有更好的方式來設計這樣的項目,而不必帶上太多額外的不必要的代碼,當我只想改變兩個項目?
很棒的功能。幫助我使用插件dll而沒有它搞亂了我的風格爲我節省了大量的工作。謝謝! – 2015-03-26 21:23:19