DataGridHyperlinkColumn DataGridHyperlinkColumn DataGridHyperlinkColumn DataGridHyperlinkColumn Class

Definition

Represents a DataGrid column that hosts Uri elements in its cells.

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
Inheritance

Examples

The following example shows a DataGridHyperlinkColumn that sets the Uri with the Binding property and the hyperlink text with the ContentBinding property. The Hyperlink.Click event is handled automatically because NavigationWindow is the parent of the 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(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal 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(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal 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

Remarks

Use DataGridHyperlinkColumn to display data that contains a Uri, such as an HTTP address or email address. The following illustration shows an example of a DataGridHyperlinkColumn.

DataGridHyperlinkColumn with email addresses

Note

Hyperlink navigation can only occur if either the direct or indirect parent of a Hyperlink is a navigation host. Examples of navigation hosts include NavigationWindow, Frame, or any browser that can host XBAPs, such as Microsoft Internet Explorer 6 or later and Firefox 2.0 or later. For more information, see the "Navigation Hosts" topic in Navigation Overview.

To populate the column, bind the column to the Uri data by using the Binding property. To display hyperlink text that is different than the URI string, bind the text value to the ContentBinding property. The Binding property is applied to the Hyperlink or TextBox element created in the column. The DataContext for the element in each cell is the data item for the row the cell is in. Therefore, to set up the binding you only have to set the Binding.Path. Optionally, you can specify a Binding.Converter if you want to convert the data. For more information about data binding, see Data Binding (WPF).

Note

DataGridHyperlinkColumn creates a Hyperlink element in the non-editing mode and a TextBox element in the editing mode.

If you want to display other types of data, DataGrid provides the following column types:

Column Type Data Display
DataGridCheckBoxColumn Use to display Boolean data.
DataGridComboBoxColumn Use to display enumeration data.
DataGridTextColumn Use to display text.

If you want to use other controls in your DataGrid, you can create your own column types by using DataGridTemplateColumn.

Constructors

DataGridHyperlinkColumn() DataGridHyperlinkColumn() DataGridHyperlinkColumn() DataGridHyperlinkColumn()

Initializes a new instance of the DataGridHyperlinkColumn class.

Fields

TargetNameProperty TargetNameProperty TargetNameProperty TargetNameProperty

Identifies the TargetName dependency property.

Properties

ActualWidth ActualWidth ActualWidth ActualWidth

Gets the current width of the column, in device-independent units (1/96th inch per unit).

(Inherited from DataGridColumn)
Binding Binding Binding Binding

Gets or sets the binding that associates the column with a property in the data source.

(Inherited from DataGridBoundColumn)
CanUserReorder CanUserReorder CanUserReorder CanUserReorder

Gets or sets a value that indicates whether the user can change the column display position by dragging the column header.

(Inherited from DataGridColumn)
CanUserResize CanUserResize CanUserResize CanUserResize

Gets or sets a value that indicates whether the user can adjust the column width by using the mouse.

(Inherited from DataGridColumn)
CanUserSort CanUserSort CanUserSort CanUserSort

Gets or sets a value that indicates whether the user can sort the column by clicking the column header.

(Inherited from DataGridColumn)
CellStyle CellStyle CellStyle CellStyle

Gets or sets the style that is used to render cells in the column.

(Inherited from DataGridColumn)
ClipboardContentBinding ClipboardContentBinding ClipboardContentBinding ClipboardContentBinding

Gets or sets the binding object to use when getting or setting cell content for the clipboard.

(Inherited from DataGridBoundColumn)
ContentBinding ContentBinding ContentBinding ContentBinding

Gets or sets the binding to the text of the hyperlink.

DataGridOwner DataGridOwner DataGridOwner DataGridOwner

Gets the DataGrid control that contains this column.

(Inherited from DataGridColumn)
DefaultEditingElementStyle DefaultEditingElementStyle DefaultEditingElementStyle DefaultEditingElementStyle

The default value of the EditingElementStyle property.

DefaultElementStyle DefaultElementStyle DefaultElementStyle DefaultElementStyle

The default value of the ElementStyle property.

DependencyObjectType DependencyObjectType DependencyObjectType DependencyObjectType

Gets the DependencyObjectType that wraps the CLR type of this instance.

(Inherited from DependencyObject)
Dispatcher Dispatcher Dispatcher Dispatcher

Gets the Dispatcher this DispatcherObject is associated with.

(Inherited from DispatcherObject)
DisplayIndex DisplayIndex DisplayIndex DisplayIndex

Gets or sets the display position of the column relative to the other columns in the DataGrid.

(Inherited from DataGridColumn)
DragIndicatorStyle DragIndicatorStyle DragIndicatorStyle DragIndicatorStyle

Gets or sets the style object to apply to the column header during a drag operation.

(Inherited from DataGridColumn)
EditingElementStyle EditingElementStyle EditingElementStyle EditingElementStyle

Gets or sets the style that is used when rendering the element that the column displays for a cell in editing mode.

(Inherited from DataGridBoundColumn)
ElementStyle ElementStyle ElementStyle ElementStyle

Gets or sets the style that is used when rendering the element that the column displays for a cell that is not in editing mode.

(Inherited from DataGridBoundColumn)
Header Header Header Header

Gets or sets the content of the column header.

(Inherited from DataGridColumn)
HeaderStringFormat HeaderStringFormat HeaderStringFormat HeaderStringFormat

Gets or sets the format pattern to apply to the content of the column header.

(Inherited from DataGridColumn)
HeaderStyle HeaderStyle HeaderStyle HeaderStyle

Gets or sets the style that is used when rendering the column header.

(Inherited from DataGridColumn)
HeaderTemplate HeaderTemplate HeaderTemplate HeaderTemplate

Gets or sets the template that defines the visual representation of the column header.

(Inherited from DataGridColumn)
HeaderTemplateSelector HeaderTemplateSelector HeaderTemplateSelector HeaderTemplateSelector

Gets or sets the object that selects which template to use for the column header.

(Inherited from DataGridColumn)
IsAutoGenerated IsAutoGenerated IsAutoGenerated IsAutoGenerated

Gets a value that indicates whether the column is auto-generated.

(Inherited from DataGridColumn)
IsFrozen IsFrozen IsFrozen IsFrozen

Gets a value that indicates whether the column is prevented from scrolling horizontally.

(Inherited from DataGridColumn)
IsReadOnly IsReadOnly IsReadOnly IsReadOnly

Gets or sets a value that indicates whether cells in the column can be edited.

(Inherited from DataGridColumn)
IsSealed IsSealed IsSealed IsSealed

Gets a value that indicates whether this instance is currently sealed (read-only).

(Inherited from DependencyObject)
MaxWidth MaxWidth MaxWidth MaxWidth

Gets or sets the maximum width constraint of the column.

(Inherited from DataGridColumn)
MinWidth MinWidth MinWidth MinWidth

Gets or sets the minimum width constraint of the column.

(Inherited from DataGridColumn)
SortDirection SortDirection SortDirection SortDirection

Gets or sets the sort direction (ascending or descending) of the column.

(Inherited from DataGridColumn)
SortMemberPath SortMemberPath SortMemberPath SortMemberPath

Gets or sets a property name, or a period-delimited hierarchy of property names, that indicates the member to sort by.

(Inherited from DataGridColumn)
TargetName TargetName TargetName TargetName

Gets or sets the name of a target window or frame for the hyperlink.

Visibility Visibility Visibility Visibility

Gets or sets the visibility of the column.

(Inherited from DataGridColumn)
Width Width Width Width

Gets or sets the column width or automatic sizing mode.

(Inherited from DataGridColumn)

Methods

CancelCellEdit(FrameworkElement, Object) CancelCellEdit(FrameworkElement, Object) CancelCellEdit(FrameworkElement, Object) CancelCellEdit(FrameworkElement, Object)

Causes the column cell being edited to revert to the specified value.

CheckAccess() CheckAccess() CheckAccess() CheckAccess()

Determines whether the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)
ClearValue(DependencyProperty) ClearValue(DependencyProperty) ClearValue(DependencyProperty) ClearValue(DependencyProperty)

Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier.

(Inherited from DependencyObject)
ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey)

Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey.

(Inherited from DependencyObject)
CoerceValue(DependencyProperty) CoerceValue(DependencyProperty) CoerceValue(DependencyProperty) CoerceValue(DependencyProperty)

Coerces the value of the specified dependency property. This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject.

(Inherited from DependencyObject)
CommitCellEdit(FrameworkElement) CommitCellEdit(FrameworkElement) CommitCellEdit(FrameworkElement) CommitCellEdit(FrameworkElement)

Performs any required validation before exiting edit mode.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether a provided DependencyObject is equivalent to the current DependencyObject.

(Inherited from DependencyObject)
GenerateEditingElement(DataGridCell, Object) GenerateEditingElement(DataGridCell, Object) GenerateEditingElement(DataGridCell, Object) GenerateEditingElement(DataGridCell, Object)

Gets an editable TextBox element that is bound to the column's ContentBinding property value.

GenerateElement(DataGridCell, Object) GenerateElement(DataGridCell, Object) GenerateElement(DataGridCell, Object) GenerateElement(DataGridCell, Object)

Gets a read-only Hyperlink element that is bound to the column's ContentBinding property value.

GetCellContent(DataGridRow) GetCellContent(DataGridRow) GetCellContent(DataGridRow) GetCellContent(DataGridRow)

Retrieves the Content property value for the cell at the intersection of this column and the specified row.

(Inherited from DataGridColumn)
GetCellContent(Object) GetCellContent(Object) GetCellContent(Object) GetCellContent(Object)

Gets the Content property value for the cell at the intersection of this column and the row that represents the specified data item.

(Inherited from DataGridColumn)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Gets a hash code for this DependencyObject.

(Inherited from DependencyObject)
GetLocalValueEnumerator() GetLocalValueEnumerator() GetLocalValueEnumerator() GetLocalValueEnumerator()

Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject.

(Inherited from DependencyObject)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetValue(DependencyProperty) GetValue(DependencyProperty) GetValue(DependencyProperty) GetValue(DependencyProperty)

Returns the current effective value of a dependency property on this instance of a DependencyObject.

(Inherited from DependencyObject)
InvalidateProperty(DependencyProperty) InvalidateProperty(DependencyProperty) InvalidateProperty(DependencyProperty) InvalidateProperty(DependencyProperty)

Re-evaluates the effective value for the specified dependency property

(Inherited from DependencyObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
NotifyPropertyChanged(String) NotifyPropertyChanged(String) NotifyPropertyChanged(String) NotifyPropertyChanged(String)

Notifies the DataGrid that contains this column that a column property has changed.

(Inherited from DataGridColumn)
OnBindingChanged(BindingBase, BindingBase) OnBindingChanged(BindingBase, BindingBase) OnBindingChanged(BindingBase, BindingBase) OnBindingChanged(BindingBase, BindingBase)

Notifies the DataGrid when the value of the Binding property changes.

(Inherited from DataGridBoundColumn)
OnCoerceIsReadOnly(Boolean) OnCoerceIsReadOnly(Boolean) OnCoerceIsReadOnly(Boolean) OnCoerceIsReadOnly(Boolean)

Determines the value of the IsReadOnly property based on property rules from the data grid that contains this column.

(Inherited from DataGridBoundColumn)
OnContentBindingChanged(BindingBase, BindingBase) OnContentBindingChanged(BindingBase, BindingBase) OnContentBindingChanged(BindingBase, BindingBase) OnContentBindingChanged(BindingBase, BindingBase)

Notifies the DataGrid when the ContentBinding property changes.

OnCopyingCellClipboardContent(Object) OnCopyingCellClipboardContent(Object) OnCopyingCellClipboardContent(Object) OnCopyingCellClipboardContent(Object)

Raises the CopyingCellClipboardContent event.

(Inherited from DataGridColumn)
OnPastingCellClipboardContent(Object, Object) OnPastingCellClipboardContent(Object, Object) OnPastingCellClipboardContent(Object, Object) OnPastingCellClipboardContent(Object, Object)

Raises the PastingCellClipboardContent event.

(Inherited from DataGridColumn)
OnPropertyChanged(DependencyPropertyChangedEventArgs) OnPropertyChanged(DependencyPropertyChangedEventArgs) OnPropertyChanged(DependencyPropertyChangedEventArgs) OnPropertyChanged(DependencyPropertyChangedEventArgs)

Invoked whenever the effective value of any dependency property on this DependencyObject has been updated. The specific dependency property that changed is reported in the event data.

(Inherited from DependencyObject)
PrepareCellForEdit(FrameworkElement, RoutedEventArgs) PrepareCellForEdit(FrameworkElement, RoutedEventArgs) PrepareCellForEdit(FrameworkElement, RoutedEventArgs) PrepareCellForEdit(FrameworkElement, RoutedEventArgs)

Called when a cell in the column enters editing mode.

ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty)

Returns the local value of a dependency property, if it exists.

(Inherited from DependencyObject)
RefreshCellContent(FrameworkElement, String) RefreshCellContent(FrameworkElement, String) RefreshCellContent(FrameworkElement, String) RefreshCellContent(FrameworkElement, String)

Refreshes the contents of a cell in the column in response to a column property value change.

SetCurrentValue(DependencyProperty, Object) SetCurrentValue(DependencyProperty, Object) SetCurrentValue(DependencyProperty, Object) SetCurrentValue(DependencyProperty, Object)

Sets the value of a dependency property without changing its value source.

(Inherited from DependencyObject)
SetValue(DependencyProperty, Object) SetValue(DependencyProperty, Object) SetValue(DependencyProperty, Object) SetValue(DependencyProperty, Object)

Sets the local value of a dependency property, specified by its dependency property identifier.

(Inherited from DependencyObject)
SetValue(DependencyPropertyKey, Object) SetValue(DependencyPropertyKey, Object) SetValue(DependencyPropertyKey, Object) SetValue(DependencyPropertyKey, Object)

Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property.

(Inherited from DependencyObject)
ShouldSerializeProperty(DependencyProperty) ShouldSerializeProperty(DependencyProperty) ShouldSerializeProperty(DependencyProperty) ShouldSerializeProperty(DependencyProperty)

Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property.

(Inherited from DependencyObject)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)
VerifyAccess() VerifyAccess() VerifyAccess() VerifyAccess()

Enforces that the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)

Events

CopyingCellClipboardContent CopyingCellClipboardContent CopyingCellClipboardContent CopyingCellClipboardContent

Occurs after the cell clipboard content is prepared.

(Inherited from DataGridColumn)
PastingCellClipboardContent PastingCellClipboardContent PastingCellClipboardContent PastingCellClipboardContent

Occurs before the clipboard content is moved to the cell.

(Inherited from DataGridColumn)

Applies to

See Also