DataGridTextColumn 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示在其儲存格中裝載文字內容的 DataGrid 數據行。
public ref class DataGridTextColumn : System::Windows::Controls::DataGridBoundColumn
public class DataGridTextColumn : System.Windows.Controls.DataGridBoundColumn
type DataGridTextColumn = class
inherit DataGridBoundColumn
Public Class DataGridTextColumn
Inherits DataGridBoundColumn
- 繼承
範例
下列範例會建立具有自定義文字數據行的 DataGrid,並使用 XML 數據做為來源。 本主題稍早的圖例顯示此程式代碼的顯示方式。 如需系結至 XML 資料的詳細資訊,請參閱 如何:使用 XMLDataProvider 和 XPath 查詢系結至 XML 數據。
<Window.Resources>
<XmlDataProvider x:Key="customerdata" Source="customers.xml" XPath="Data" />
</Window.Resources>
<Grid>
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Source={StaticResource customerdata}, XPath=Customer}">
<DataGrid.Columns>
<DataGridTextColumn Header="First Name" Binding="{Binding XPath=@FirstName}" FontFamily="Arial" FontStyle="Italic" />
<DataGridTextColumn Header="Last Name" Binding="{Binding XPath=@LastName}" FontFamily="Arial" FontWeight="Bold" />
</DataGrid.Columns>
</DataGrid>
</Grid>
備註
使用 DataGridTextColumn 將數據行顯示為文字。 下圖顯示兩個 DataGridTextColumn 類型的範例。
若要建立數據行,請將它新增至 Columns 集合。 若要填入數據行,請使用 Binding 屬性將數據行系結至數據。 Binding 屬性會套用至數據行中建立的 TextBlock 或 TextBox 專案。 每個數據格中元素的 DataContext 是儲存格所屬數據列的數據項。 因此,若要設定系結,您只需要設定 Binding.Path。 如果您想要轉換資料或 StringFormat,您可以選擇指定 Binding.Converter。 如需資料系結的詳細資訊,請參閱 數據系結 (WPF)。
NoteDataGridTextColumn 會在非編輯模式中建立 TextBlock 專案,並在編輯模式中建立 TextBox 專案。
您可以藉由設定屬性來自定義 DataGridTextColumn,例如 Width、Header、FontSize和 IsReadOnly。
如果您要顯示其他類型的數據,DataGrid 提供下列資料行類型:
| 數據行類型 | 數據顯示 |
|---|---|
| DataGridHyperlinkColumn | 用來顯示 URI 數據。 |
| DataGridComboBoxColumn | 用來顯示列舉數據。 |
| DataGridCheckBoxColumn | 用來顯示布爾數據。 |
如果您想要在 DataGrid中使用其他控制件,您可以使用 DataGridTemplateColumn建立自己的資料行類型。
建構函式
| DataGridTextColumn() |
初始化 DataGridTextColumn 類別的新實例。 |
欄位
| FontFamilyProperty |
識別 FontFamily 相依性屬性。 |
| FontSizeProperty |
識別 FontSize 相依性屬性。 |
| FontStyleProperty |
識別 FontStyle 相依性屬性。 |
| FontWeightProperty |
識別 FontWeight 相依性屬性。 |
| ForegroundProperty |
識別 Foreground 相依性屬性。 |
屬性
| ActualWidth |
取得數據行的目前寬度,以裝置獨立單位為單位(每單位 1/96 英吋)。 (繼承來源 DataGridColumn) |
| Binding |
取得或設定系結,這個系結會將數據行與數據源中的屬性產生關聯。 (繼承來源 DataGridBoundColumn) |
| CanUserReorder |
取得或設定值,這個值表示使用者是否可以藉由拖曳數據行標頭來變更數據行顯示位置。 (繼承來源 DataGridColumn) |
| CanUserResize |
取得或設定值,指出使用者是否可以使用滑鼠調整數據行寬度。 (繼承來源 DataGridColumn) |
| CanUserSort |
取得或設定值,這個值表示使用者是否可以按下數據行標頭來排序數據行。 (繼承來源 DataGridColumn) |
| CellStyle |
取得或設定用來呈現數據行中儲存格的樣式。 (繼承來源 DataGridColumn) |
| ClipboardContentBinding |
取得或設定剪貼簿的儲存格內容時要使用的系結物件。 (繼承來源 DataGridBoundColumn) |
| DataGridOwner |
取得包含這個數據行的 DataGrid 控制件。 (繼承來源 DataGridColumn) |
| DefaultEditingElementStyle |
EditingElementStyle 屬性的預設值。 |
| DefaultElementStyle |
ElementStyle 屬性的預設值。 |
| DependencyObjectType |
取得包裝這個實例 CLR 類型的 DependencyObjectType。 (繼承來源 DependencyObject) |
| Dispatcher |
取得與這個 DispatcherObject 相關聯的 Dispatcher。 (繼承來源 DispatcherObject) |
| DisplayIndex |
取得或設定數據行相對於 DataGrid中其他數據行的顯示位置。 (繼承來源 DataGridColumn) |
| DragIndicatorStyle |
取得或設定在拖曳作業期間套用至數據行標頭的樣式物件。 (繼承來源 DataGridColumn) |
| EditingElementStyle |
取得或設定在編輯模式中轉譯數據行針對儲存格顯示的專案時所使用的樣式。 (繼承來源 DataGridBoundColumn) |
| ElementStyle |
取得或設定在轉譯數據行針對不在編輯模式之單元格顯示的專案時所使用的樣式。 (繼承來源 DataGridBoundColumn) |
| FontFamily |
取得或設定數據行中儲存格內容的字型系列。 |
| FontSize |
取得或設定數據行中儲存格內容的字型大小。 |
| FontStyle |
取得或設定數據行中儲存格內容的字型樣式。 |
| FontWeight |
取得或設定數據行中儲存格內容的字型粗細。 |
| Foreground |
取得或設定用來繪製數據行中儲存格文字內容的 Brush。 |
| 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) |
方法
事件
| CopyingCellClipboardContent |
發生於備妥單元格剪貼簿內容之後。 (繼承來源 DataGridColumn) |
| PastingCellClipboardContent |
發生於剪貼簿內容移至儲存格之前。 (繼承來源 DataGridColumn) |