共用方式為


DataGridTemplateColumn 類別

定義

代表 DataGrid 一個欄位,其儲存格中承載模板指定的內容。

public ref class DataGridTemplateColumn : System::Windows::Controls::DataGridColumn
public class DataGridTemplateColumn : System.Windows.Controls.DataGridColumn
type DataGridTemplateColumn = class
    inherit DataGridColumn
Public Class DataGridTemplateColumn
Inherits DataGridColumn
繼承

範例

以下範例說明如何建立 DataGridTemplateColumn

<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 的欄位

備註

這個 DataGridTemplateColumn 型別讓你能透過指定顯示和編輯值時使用的儲存格模板,建立自己的欄位類型。 若要指定用於顯示非編輯模式儲存格內容的範本,請設定屬性 CellTemplate 。 若要指定用於顯示編輯模式儲存格內容的範本,請設定屬性 CellEditingTemplate 。 欲了解更多範本資訊,請參閱 資料模板概述樣式與模板

為方便起見, DataGrid 提供以下預先定義的欄位類型:

欄位類型 資料顯示
DataGridHyperlinkColumn 用來顯示 URI 資料。
DataGridComboBoxColumn 用來顯示列舉資料。
DataGridTextColumn 用來顯示文字。
DataGridCheckBoxColumn 用來顯示布林資料。

建構函式

名稱 Description
DataGridTemplateColumn()

初始化 DataGridTemplateColumn 類別的新執行個體。

欄位

名稱 Description
CellEditingTemplateProperty

識別 CellEditingTemplate 依賴性質。

CellEditingTemplateSelectorProperty

識別 CellEditingTemplateSelector 依賴性質。

CellTemplateProperty

識別 CellTemplate 依賴性質。

CellTemplateSelectorProperty

識別 CellEditingTemplateSelector 依賴性質。

屬性

名稱 Description
ActualWidth

取得該柱目前的寬度,單位與裝置無關(每單位1/96英吋)。

(繼承來源 DataGridColumn)
CanUserReorder

取得或設定一個值,指示使用者是否可以透過拖動欄位標頭來改變欄位顯示位置。

(繼承來源 DataGridColumn)
CanUserResize

取得或設定一個值,指示使用者是否能透過滑鼠調整欄位寬度。

(繼承來源 DataGridColumn)
CanUserSort

取得或設定一個值,指示使用者是否能透過點擊欄位標頭來排序該欄位。

(繼承來源 DataGridColumn)
CellEditingTemplate

取得或設定範本,用來顯示處於編輯模式的儲存格內容。

CellEditingTemplateSelector

取得或設定物件,決定使用哪個範本來顯示處於編輯模式的儲存格內容。

CellStyle

取得或設定用於渲染欄位中儲存格的樣式。

(繼承來源 DataGridColumn)
CellTemplate

取得或設定範本,用來顯示非編輯模式儲存格的內容。

CellTemplateSelector

取得或設定物件,決定使用哪個範本來顯示非編輯模式的儲存格內容。

ClipboardContentBinding

取得或設定綁定物件,以便在取得或設定剪貼簿的儲存格內容時使用。

(繼承來源 DataGridColumn)
DataGridOwner

取得 DataGrid 包含此欄位的控制項。

(繼承來源 DataGridColumn)
DependencyObjectType

會取得 DependencyObjectType 包裹此實例 CLR 類型的 。

(繼承來源 DependencyObject)
Dispatcher

了解 Dispatcher 這與此 DispatcherObject 有關。

(繼承來源 DispatcherObject)
DisplayIndex

取得或設定該欄位相對於其他欄位 DataGrid的顯示位置。

(繼承來源 DataGridColumn)
DragIndicatorStyle

在拖曳操作中取得或設定樣式物件套用到欄位標頭。

(繼承來源 DataGridColumn)
Header

取得或設定欄位標頭的內容。

(繼承來源 DataGridColumn)
HeaderStringFormat

取得或設定格式模式,以套用到欄位標頭的內容。

(繼承來源 DataGridColumn)
HeaderStyle

取得或設定在渲染欄位標頭時所使用的樣式。

(繼承來源 DataGridColumn)
HeaderTemplate

取得或設定定義欄位標頭視覺表示的範本。

(繼承來源 DataGridColumn)
HeaderTemplateSelector

取得或設定物件,選擇欄位標頭使用哪個範本。

(繼承來源 DataGridColumn)
IsAutoGenerated

會得到一個值,表示欄位是否自動產生。

(繼承來源 DataGridColumn)
IsFrozen

會得到一個值,表示欄位是否被阻止橫向捲動。

(繼承來源 DataGridColumn)
IsReadOnly

取得或設定一個值,指示欄位中是否可以編輯儲存格。

(繼承來源 DataGridColumn)
IsSealed

會獲得一個值,表示該實例目前是否封存(唯讀)。

(繼承來源 DependencyObject)
MaxWidth

取得或設定欄位的最大寬度限制。

(繼承來源 DataGridColumn)
MinWidth

取得或設定欄位的最小寬度限制。

(繼承來源 DataGridColumn)
SortDirection

取得或設定欄位的排序方向(向上或向下)。

(繼承來源 DataGridColumn)
SortMemberPath

取得或設定一個屬性名稱,或一個以時間劃分的屬性名稱階層,指示要排序的成員。

(繼承來源 DataGridColumn)
Visibility

取得或設定欄位的可見性。

(繼承來源 DataGridColumn)
Width

可以設定欄位寬度或自動尺寸模式。

(繼承來源 DataGridColumn)

方法

名稱 Description
CancelCellEdit(FrameworkElement, Object)

會讓被編輯的儲存格回復到原始、未編輯的值。

(繼承來源 DataGridColumn)
CheckAccess()

判斷呼叫執行緒是否能存取此 DispatcherObject

(繼承來源 DispatcherObject)
ClearValue(DependencyProperty)

清算房產的當地價值。 要清除的屬性由識別 DependencyProperty 碼指定。

(繼承來源 DependencyObject)
ClearValue(DependencyPropertyKey)

清除只讀屬性的局部值。 要清除的屬性由 DependencyPropertyKey指定。

(繼承來源 DependencyObject)
CoerceValue(DependencyProperty)

強制設定指定的依賴性質值。 這是透過在屬性CoerceValueCallback中指定的依賴屬性元資料中,呼叫 的依賴屬性中的任何DependencyObject函式來達成的。

(繼承來源 DependencyObject)
CommitCellEdit(FrameworkElement)

在退出儲存格編輯模式前,執行任何必要的驗證。

(繼承來源 DataGridColumn)
Equals(Object)

判斷所給的 DependencyObject 是否等同於電流 DependencyObject

(繼承來源 DependencyObject)
GenerateEditingElement(DataGridCell, Object)

會得到一個 CellEditingTemplate 由 定義的元素,該元素綁定於該欄位的 Binding 屬性值。

GenerateElement(DataGridCell, Object)

會得到一個 CellTemplate 由 定義的元素,該元素綁定於該欄位的 Binding 屬性值。

GetCellContent(DataGridRow)

取得 Content 該欄位與指定列交點的儲存格屬性值。

(繼承來源 DataGridColumn)
GetCellContent(Object)

取得 Content 該欄位與代表指定資料項目的列交點儲存格的屬性值。

(繼承來源 DataGridColumn)
GetHashCode()

會得到一個 DependencyObject雜湊碼。

(繼承來源 DependencyObject)
GetLocalValueEnumerator()

建立專門的枚舉器,用以判斷哪些相依屬性在局部 DependencyObject設定值。

(繼承來源 DependencyObject)
GetType()

取得目前實例的 Type

(繼承來源 Object)
GetValue(DependencyProperty)

回傳此實例 DependencyObject上依賴屬性的當前有效值。

(繼承來源 DependencyObject)
InvalidateProperty(DependencyProperty)

重新評估指定相依性質的有效值。

(繼承來源 DependencyObject)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
NotifyPropertyChanged(String)

通知 DataGrid 包含此欄位的 欄位屬性已變更。

(繼承來源 DataGridColumn)
OnCoerceIsReadOnly(Boolean)

根據包含此欄位的DataGrid屬性規則來決定該財產的價值IsReadOnly

(繼承來源 DataGridColumn)
OnCopyingCellClipboardContent(Object)

引發 CopyingCellClipboardContent 事件。

(繼承來源 DataGridColumn)
OnPastingCellClipboardContent(Object, Object)

引發 PastingCellClipboardContent 事件。

(繼承來源 DataGridColumn)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

當任何依賴性財產 DependencyObject 的實際價值更新時,該權利會被調用。 變更的具體相依屬性會在事件資料中報告。

(繼承來源 DependencyObject)
PrepareCellForEdit(FrameworkElement, RoutedEventArgs)

當在衍生類別中覆寫時,會根據編輯所需的儲存格內容設定。

(繼承來源 DataGridColumn)
ReadLocalValue(DependencyProperty)

回傳依賴屬性的局部值(若存在)。

(繼承來源 DependencyObject)
RefreshCellContent(FrameworkElement, String)

當範本屬性值變更時,會刷新欄位中儲存格的內容。

SetCurrentValue(DependencyProperty, Object)

設定依賴屬性的值,且不改變其值來源。

(繼承來源 DependencyObject)
SetValue(DependencyProperty, Object)

設定依賴屬性的局部值,並由其依賴屬性識別碼指定。

(繼承來源 DependencyObject)
SetValue(DependencyPropertyKey, Object)

設定只讀相依屬性的本地值,該值由 DependencyPropertyKey 相依屬性的識別碼指定。

(繼承來源 DependencyObject)
ShouldSerializeProperty(DependencyProperty)

回傳一個值,指示序列化程序是否應該將所提供的相依屬性的值序列化。

(繼承來源 DependencyObject)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)
VerifyAccess()

強制呼叫執行緒能存取此 DispatcherObject

(繼承來源 DispatcherObject)

事件

名稱 Description
CopyingCellClipboardContent

發生在儲存區剪貼板內容準備完成後。

(繼承來源 DataGridColumn)
PastingCellClipboardContent

發生在剪貼簿內容移動到儲存格之前。

(繼承來源 DataGridColumn)

適用於

另請參閱