728x90
반응형
728x170

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
반응형
그리드형
Posted by kjun

댓글을 달아 주세요