728x90
GridControl Focus Row/Cell Color 변경하는 방법은 GridControl 내부의 TableView 선언 시 Style 를 정의하여 변경이 가능하다.
Style정의
<Style x:Key="FocusedCellStyle" TargetType="dxg:LightweightCellEditor">
<Style.Triggers>
<Trigger Property="dxg:DataViewBase.IsFocusedCell" Value="True">
<Setter Property="Background" Value="Green" />
<Setter Property="Foreground" Value="Yellow" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="FocusedRowStyle" TargetType="dxg:RowControl">
<Style.Triggers>
<Trigger Property="dxg:DataViewBase.IsFocusedRow" Value="True">
<Setter Property="Background" Value="Gray" />
<Setter Property="Foreground" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
GridControl 에서 사용 위 정의한 Style 를 사용한다.
<dxg:GridControl Height="300" ItemsSource="{Binding Items}">
<dxg:GridColumn FieldName="CellColor" Header="COLOR">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<Border Background="{Binding Data}" />
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
<dxg:GridColumn FieldName="Name" Header="NAME" />
<dxg:GridColumn FieldName="Age" Header="AGE" />
<dxg:GridControl.View>
<dxg:TableView
CellStyle="{StaticResource FocusedCellStyle}"
RowStyle="{StaticResource FocusedRowStyle}"
ShowGroupPanel="False" />
</dxg:GridControl.View>
</dxg:GridControl>
결과
위처럼 GridControl Focus Row/Cell Color 가 변경된걸 확인할 수 있다.
전체 코드
<Window
x:Class="Wpf.DevGridTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:local="clr-namespace:Wpf.DevGridTest"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow"
Width="800"
Height="450"
mc:Ignorable="d">
<Window.Resources>
<Style x:Key="FocusedCellStyle" TargetType="dxg:LightweightCellEditor">
<Style.Triggers>
<Trigger Property="dxg:DataViewBase.IsFocusedCell" Value="True">
<Setter Property="Background" Value="Green" />
<Setter Property="Foreground" Value="Yellow" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="FocusedRowStyle" TargetType="dxg:RowControl">
<Style.Triggers>
<Trigger Property="dxg:DataViewBase.IsFocusedRow" Value="True">
<Setter Property="Background" Value="Gray" />
<Setter Property="Foreground" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<dxg:GridControl Height="300" ItemsSource="{Binding Items}">
<dxg:GridColumn FieldName="CellColor" Header="COLOR">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<Border Background="{Binding Data}" />
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
<dxg:GridColumn FieldName="Name" Header="NAME" />
<dxg:GridColumn FieldName="Age" Header="AGE" />
<dxg:GridControl.View>
<dxg:TableView
CellStyle="{StaticResource FocusedCellStyle}"
RowStyle="{StaticResource FocusedRowStyle}"
ShowGroupPanel="False" />
</dxg:GridControl.View>
</dxg:GridControl>
</Grid>
</Window>
소스
https://github.com/kei-soft/KJunBlog/tree/master/Wpf.DevGridTest
728x90
'DevExpress' 카테고리의 다른 글
[DevExpress/WPF] TrackBarEdit 소숫점처리 (0) | 2022.08.30 |
---|---|
[DevExpress/WPF] TrackBarEdit 사용하기 - Dual(Range) Slider (0) | 2022.08.30 |
[DevExpress] BandedGridView 에서 컬럼 이동 막기 (0) | 2020.06.05 |
[DevExpress] XtraGrid 의 데이터 없는 경우 표시 하기 (0) | 2020.06.05 |
[DevExpress] XtraGrid Copy 시 컬럼 헤더 포함시키기 (0) | 2020.05.27 |