DataGridTemplateColumn.CellEditingTemplate 属性

定义

获取或设置模板,该模板用于显示处于编辑模式的单元格的内容。

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

属性值

DataTemplate

用于显示处于编辑模式的单元格的内容的模板。 已注册的默认值为 null。 有关可能影响该值的因素的信息,请参见 DependencyProperty

示例

以下示例演示如何创建 CellEditingTemplate 用于显示和编辑日期列的列。

<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 的列

注解

在编辑模式下,单元格编辑模板定义内容在列单元格中的显示方式。 有关数据模板的详细信息,请参阅 数据模板化概述样式设置和模板化

若要为不在编辑模式下的单元格定义模板,请使用 .CellTemplate

适用于

另请参阅