첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

▶ XAML

<Grid
    xmlns:local="clr-namespace:HowToSelectTemplatesBasedOnCustomLogic"
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid">
    <Grid.Resources>
        <local:RowDataTemplateSelector x:Key="RowDataTemplateSelectorKey" />
        <DataTemplate x:Key="EvenRowDataTemplateKey">
            <Border
                Margin="3"
                CornerRadius="5"
                Background="Blue">
                <TextBlock
                    Margin="5"
                    Foreground="White"
                    Text="{Binding DataContext.IssueName}" />
            </Border>
        </DataTemplate>
        <DataTemplate x:Key="OddRowDataTemplateKey">
            <Border
                Margin="3"
                CornerRadius="5"
                Background="Orange">
                <TextBlock
                    Margin="5"
                    Foreground="White"
                    Text="{Binding DataContext.IssueName}" />
            </Border>
        </DataTemplate>
    </Grid.Resources>
    <dxg:GridControl x:Name="gridControl"
        AutoGenerateColumns="AddNew">
        <dxg:GridControl.View>
            <dxg:TableView
                ShowIndicator="False"
                ShowGroupPanel="False"
                ShowColumnHeaders="False"
                ShowHorizontalLines="False"
                DataRowTemplateSelector="{StaticResource RowDataTemplateSelectorKey}" />
        </dxg:GridControl.View>
    </dxg:GridControl>
</Grid>

 

728x90

 

▶ C#

using System.Windows;
using System.Windows.Controls;

using DevExpress.Xpf.Grid;

/// <summary>
/// 행 데이터 템플리트 선택자
/// </summary>
public class RowDataTemplateSelector : DataTemplateSelector
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 템플리트 선택하기 - SelectTemplate(utem, container)

    /// <summary>
    /// 템플리트 선택하기
    /// </summary>
    /// <param name="item">항목</param>
    /// <param name="container">컨테이너</param>
    /// <returns>DataTemplate 객체</returns>
    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
        RowData          rowData                   = item      as RowData;
        FrameworkElement containerFrameworkElement = container as FrameworkElement;

        if(rowData != null && containerFrameworkElement != null)
        {
            return rowData.EvenRow ? containerFrameworkElement.FindResource("EvenRowDataTemplateKey") as DataTemplate:
                                     containerFrameworkElement.FindResource("OddRowDataTemplateKey" ) as DataTemplate;
        }

        return base.SelectTemplate(item, container);
    }

    #endregion
}

 

728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요