DataGridTemplateColumn.CellTemplate 속성

정의

편집 모드에 있지 않은 셀의 내용을 표시하는 데 사용할 템플릿을 가져오거나 설정합니다.

public:
 property System::Windows::DataTemplate ^ CellTemplate { System::Windows::DataTemplate ^ get(); void set(System::Windows::DataTemplate ^ value); };
public System.Windows.DataTemplate CellTemplate { get; set; }
member this.CellTemplate : System.Windows.DataTemplate with get, set
Public Property CellTemplate As DataTemplate

속성 값

DataTemplate

편집 모드에 있지 않은 셀의 내용을 표시하는 데 사용할 템플릿입니다. 등록된 기본값은 null입니다. 값에 영향을 줄 수 있는 요소에 대한 자세한 내용은 DependencyProperty를 참조하십시오.

예제

다음 예제에서는 만드는 방법을 보여 줍니다는 CellTemplate 날짜 열을 표시 합니다.

<Grid>
    <Grid.Resources>
        <!--DataTemplate for Published Date column defined in Grid.Resources.  PublishDate is a property on the ItemsSource of type DateTime -->
        <DataTemplate x:Key="DateTemplate" >
            <StackPanel Width="20" Height="30">
                <Border Background="LightBlue" BorderBrush="Black" BorderThickness="1">
                    <TextBlock Text="{Binding PublishDate, StringFormat={}{0:MMM}}" FontSize="8" HorizontalAlignment="Center" />
                </Border>
                <Border Background="White" BorderBrush="Black" BorderThickness="1">
                    <TextBlock Text="{Binding PublishDate, StringFormat={}{0:yyyy}}" FontSize="8" FontWeight="Bold" HorizontalAlignment="Center" />
                </Border>
            </StackPanel>
        </DataTemplate>
        <!--DataTemplate for the Published Date column when in edit mode. -->
        <DataTemplate x:Key="EditingDateTemplate">
            <DatePicker SelectedDate="{Binding PublishDate}"  />
        </DataTemplate>
    </Grid.Resources>
    <DataGrid Name="DG1" ItemsSource="{Binding}" AutoGenerateColumns="False" >
        <DataGrid.Columns>
            <!--Custom column that shows the published date-->
            <DataGridTemplateColumn Header="Publish Date" CellTemplate="{StaticResource DateTemplate}" CellEditingTemplate="{StaticResource EditingDateTemplate}" />
        </DataGrid.Columns>
    </DataGrid>
</Grid>

다음 그림에서는 이전 XAML에서 출력을 보여줍니다.

DataTemplate을 사용하는 열

설명

셀 템플릿이 열 셀의 내용을 표시 하는 방법을 정의 합니다. 데이터 템플릿에 대 한 자세한 내용은 참조 하세요. 데이터 템플릿 개요 하 고 스타일 및 템플릿합니다.

편집 모드에 있는 셀의 템플릿을 정의 하려면 사용 된 CellEditingTemplate합니다.

적용 대상

추가 정보