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

屬性值

用來顯示處於編輯模式的儲存格內容的範本。 註冊預設為 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

適用於

另請參閱