[C# WPF][DevExpress] Bands GridControl 열 셀 색깔 넣기

728x90

기본적으로 Bands 를 활용한 표는 행만 제목으로 추가가 되지 열은 제목(?)으로 추가가 되지 않는다.

대신 열을 같은 데이터끼리 묶을 수 있다. 표의 양식임을 알 수 있도록 GridControl 에 셀 색깔을 넣어 줄 수 있다.

 

                <dxg:GridControlBand Header="헤더1">

                    <dxg:GridColumn FieldName="BlockType" Header="헤더2">
                        
                        <!-- 해당 셀에 색깔 넣기 -->
                        <dxg:GridColumn.CellTemplate>
                            <DataTemplate>
                                <Border Background="yellow"/>
                            </DataTemplate>
                        </dxg:GridColumn.CellTemplate>
                    </dxg:GridColumn>

저렇게 하니까 GridColum에 Binding 했을 때 텍스트가 덮혀서 아래와 같이 처리했다.

 

 
    ...
    
    <UserControl.Resources>
        <Style x:Key="cellStyle" TargetType="dxg:LightweightCellEditor">
            <Setter Property="Background" Value="Yellow" />
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="HorizontalAlignment" Value="Center"/>
        </Style>
        
    </UserControl.Resources>
    
    ...
    
    
                <dxg:GridControl.Bands >
                <dxg:GridControlBand Header="헤더1">

                    <dxg:GridColumn FieldName="BlockType" Header="헤더2" AllowCellMerge="True"  Binding="{Binding BlockType}" CellStyle="{StaticResource cellStyle}"/>
                    
                    ...
728x90