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

適用於

另請參閱