views:

1936

answers:

4

I'm using WPFToolkit's Datagrid control. I can populate the datagrid, but I'm having trouble with the DataGridHyperlinkColumn. I would like it to visually display the link as the Person's name, but for the link to go to whatever UriLink's value is.

How can I do this? What am I doing wrong?

Xaml:

<dg:DataGridHyperlinkColumn Header="Person Name" Width="200" 
Binding="{Binding Path=PersonName}" IsReadOnly="True" 
TargetName="{Binding Path=UriLink}"></dg:DataGridHyperlinkColumn>

Alternatively, I would rather put an event handler in instead, and create the page object to navigate to, but I can't seem to pull any data out of the event's two parameters (o and e in this case), where obj1/obj2 are objects/variables of the clicked hyperlink's row.

Alternative Xaml:

<dg:DataGridHyperlinkColumn Header="Person Name" Width="200" 
Binding="{Binding Path=PersonName}" IsReadOnly="True" 
TargetName="{Binding Path=UriLink}">
    <dg:DataGridHyperlinkColumn.ElementStyle>
    <Style TargetType="TextBlock">
    <EventSetter Event="Hyperlink.Click" Handler="OnHyperlinkClick" />
    </Style>
    </dg:DataGridHyperlinkColumn.ElementStyle>
    </dg:DataGridHyperlinkColumn>

VB code (for Alternative Xaml):

Private Sub OnHyperlinkClick(ByVal o As Object, ByVal e As RoutedEventArgs)

        'TODO: Create page to navigate to
        Dim page As New RedirectPage(obj1, obj2)
        Me.NavigationService.Navigate(page)

End Sub
A: 

Maybe the Hyperlink.RequestNavigate event would work better? It looks like the EventArgs contains the URI that the navigation target is, which should be the URI of the hyperlink control itself.

Andy
+1  A: 

Cast o as a TextBlock, it's DataContext is your row's object. You can cast it as your object type.

A: 

As AKCODer said, it's in the DataContext. Using the OnHyperlinkClick event handler, I used the following:

DirectCast(DirectCast(DirectCast(e.Source, System.Object), System.Windows.Documents.Hyperlink).DataContext, System.Object)
sunpech
A: 

hi , when i use the same logic i'm getting the following error "Error 1 The Element type 'Microsoft.Windows.Controls.DataGridHyperlinkColumn' does not have an associated TypeConverter to parse the string '"

I working on c#.net