共用方式為


DataGridHyperlinkColumn 類別

定義

代表 DataGrid 一欄,其儲存格中包含 Uri 元素。

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

範例

以下範例展示了DataGridHyperlinkColumn將 設定為 Binding 屬性的 ,Uri以及將超連結文字設定為 屬性ContentBindingHyperlink.Click該事件會自動處理,因為NavigationWindow是 的父DataGrid節點。

<NavigationWindow x:Class="DataGrid_CustomColumns.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:core="clr-namespace:System;assembly=mscorlib"
    xmlns:local="clr-namespace:DataGrid_CustomColumns"
    Title="Customers" Height="300" Width="300" ShowsNavigationUI="False"  >
    
<NavigationWindow.Resources>
    <!--Create an instance of the converter for Email-->
    <local:EmailConverter x:Key="EmailConverter" />
</NavigationWindow.Resources>
<NavigationWindow.Content>  
    
<Grid>
    <DataGrid Name="DG1" ItemsSource="{Binding}" AutoGenerateColumns="False" >
        <DataGrid.Columns>
<!--The Email property contains a URI.  For example "mailto:lucy0@adventure-works.com"-->
<DataGridHyperlinkColumn Header="Email" Binding="{Binding Email}"  ContentBinding="{Binding Email, Converter={StaticResource EmailConverter}}" />
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
    </NavigationWindow.Content>
</NavigationWindow>
public partial class Window1 : NavigationWindow
{
Class Window1
public Window1()
{
    InitializeComponent();

    //GetData() creates a collection of Customer data from a database
    ObservableCollection<Customer> custdata = GetData();
    
    //Bind the DataGrid to the customer data
    DG1.DataContext = custdata;
}
Public Sub New()
    ' This call is required by the Windows Form Designer.
    InitializeComponent()
    ' Add any initialization after the InitializeComponent() call.

    'GetData() creates a collection of Customer data from a database
    Dim custdata As ObservableCollection(Of Customer) = GetData()

    'Bind the DataGrid to the customer data
    DG1.DataContext = custdata

End Sub
//Defines the customer object
public class Customer
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public Uri Email { get; set; }
    public bool IsMember { get; set; }
    public OrderStatus Status { get; set; }
}
'Defines the customer object
Public Class Customer
    Public Property FirstName() As String
    Public Property LastName() As String
    Public Property Email() As Uri
    Public Property IsMember() As Boolean
    Public Property Status() As OrderStatus
End Class
}
End Class
//Converts the mailto uri to a string with just the customer alias
public class EmailConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value != null)
        {
            string email = value.ToString();
            int index = email.IndexOf("@");
            string alias = email.Substring(7, index-7);
            return alias;
        }
        else
        {
            string email = "";
            return email;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        Uri email = new Uri((string)value);
        return email;
    }
}
'Converts the mailto uri to a string with just the customer alias
Public Class EmailConverter
    Implements IValueConverter

    Public Function Convert(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        If value IsNot Nothing Then
            Dim email As String = value.ToString()
            Dim index As Integer = email.IndexOf("@")
            Dim [alias] As String = email.Substring(7, index - 7)
            Return [alias]
        Else
            Dim email As String = ""
            Return email
        End If
    End Function

    Public Function ConvertBack(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Dim email As New Uri(DirectCast(value, String))
        Return email
    End Function
End Class

備註

用於 DataGridHyperlinkColumn 顯示包含 Uri的資料,例如 HTTP 位址或電子郵件地址。 下圖顯示 DataGridHyperlinkColumn 範例。

DataGridHyperlinkColumn 含電子郵件地址

備註

Hyperlink 只有當 A Hyperlink 的直接或間接父節點是導航主機時,才能進行導航。 導航主機的例子包括 NavigationWindowFrame,或任何能承載 XBAP 的瀏覽器。 更多資訊請參閱「導航主機」條目中的 導航概覽

欲了解更多關於 XBAP 支援的資訊,請參閱 關於 WPF 瀏覽器託管應用程式(XBAP)的常見問題

要填充欄位,請使用 屬性Binding將欄位綁定到資料。Uri 若要顯示與 URI 字串不同的超連結文字,請將文字值綁定到屬性 ContentBinding 上。 該 Binding 屬性會套用到 Hyperlink 欄位中所建立的 or TextBox 元素。 每個儲存格中的元素 是 DataContext 該儲存格所在資料列的資料項目。 因此,要設定綁定,你只需要設定 Binding.Path。 如果你想轉換資料,也可以選擇指定 a Binding.Converter 。 欲了解更多資料綁定資訊,請參閱資料綁定(WPF)。

備註

DataGridHyperlinkColumn 在非編輯模式下建立一個 Hyperlink 元素,在編輯模式下建立一個 TextBox 元素。

若您想顯示其他類型的資料, DataGrid 提供以下欄位類型:

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

如果你想在 中使用其他控制項, DataGrid可以透過使用 DataGridTemplateColumn

建構函式

名稱 Description
DataGridHyperlinkColumn()

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

欄位

名稱 Description
TargetNameProperty

識別 TargetName 依賴性質。

屬性

名稱 Description
ActualWidth

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

(繼承來源 DataGridColumn)
Binding

取得或設定將欄位與資料來源屬性關聯的綁定。

(繼承來源 DataGridBoundColumn)
CanUserReorder

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

(繼承來源 DataGridColumn)
CanUserResize

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

(繼承來源 DataGridColumn)
CanUserSort

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

(繼承來源 DataGridColumn)
CellStyle

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

(繼承來源 DataGridColumn)
ClipboardContentBinding

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

(繼承來源 DataGridBoundColumn)
ContentBinding

取得或設定綁定到超連結的文字上。

DataGridOwner

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

(繼承來源 DataGridColumn)
DefaultEditingElementStyle

房產的預設價值 EditingElementStyle

DefaultElementStyle

房產的預設價值 ElementStyle

DependencyObjectType

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

(繼承來源 DependencyObject)
Dispatcher

了解 Dispatcher 這與此 DispatcherObject 有關。

(繼承來源 DispatcherObject)
DisplayIndex

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

(繼承來源 DataGridColumn)
DragIndicatorStyle

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

(繼承來源 DataGridColumn)
EditingElementStyle

取得或設定在渲染欄位中儲存格時所使用的樣式。

(繼承來源 DataGridBoundColumn)
ElementStyle

取得或設定在渲染欄位中顯示元素時所使用的樣式,該欄位顯示的儲存格並非處於編輯模式。

(繼承來源 DataGridBoundColumn)
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)
TargetName

取得或設定超連結的目標視窗或框架名稱。

Visibility

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

(繼承來源 DataGridColumn)
Width

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

(繼承來源 DataGridColumn)

方法

名稱 Description
CancelCellEdit(FrameworkElement, Object)

會讓被編輯的欄位儲存格回復到指定的值。

CancelCellEdit(FrameworkElement, Object)

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

(繼承來源 DataGridColumn)
CheckAccess()

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

(繼承來源 DispatcherObject)
ClearValue(DependencyProperty)

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

(繼承來源 DependencyObject)
ClearValue(DependencyPropertyKey)

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

(繼承來源 DependencyObject)
CoerceValue(DependencyProperty)

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

(繼承來源 DependencyObject)
CommitCellEdit(FrameworkElement)

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

CommitCellEdit(FrameworkElement)

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

(繼承來源 DataGridColumn)
Equals(Object)

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

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

會獲得一個可編輯 TextBox 的元素,該元素綁定於欄位的 ContentBinding 屬性值。

GenerateElement(DataGridCell, Object)

會獲得一個只讀 Hyperlink 元素,綁定於該欄位的 ContentBinding 屬性值。

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)
OnBindingChanged(BindingBase, BindingBase)

當房產價值Binding變動時會通知DataGrid

(繼承來源 DataGridBoundColumn)
OnCoerceIsReadOnly(Boolean)

根據包含此欄位的資料網格中的屬性規則,決定屬性的 IsReadOnly 價值。

(繼承來源 DataGridBoundColumn)
OnContentBindingChanged(BindingBase, BindingBase)

當物業變更時ContentBinding會通知他們DataGrid

OnCopyingCellClipboardContent(Object)

引發 CopyingCellClipboardContent 事件。

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

引發 PastingCellClipboardContent 事件。

(繼承來源 DataGridColumn)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

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

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

當欄位中的儲存格進入編輯模式時會被呼叫。

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)

適用於

另請參閱