Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
Hyperlink in Grid
posted

I'm trying to leverage a hyperlink my xamDataGrid so that clicking on the text fires an event to my viewmodel with unique ID associated with my row.

<Style x:Key="HyperlinkStyle" TargetType="{x:Type igDP:CellValuePresenter}">

<Setter Property="Template">

<Setter.Value>

<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">

<TextBlock Margin="{TemplateBinding Padding}" VerticalAlignment="Center" TextAlignment="Left"><Hyperlink Click="Navigate" Tag="{Binding}" >

<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path =Value}"/>

</Hyperlink>

</TextBlock>

</ControlTemplate>

</Setter.Value>

</Setter>

</Style>

I can figure out which row's hyperlink has been clicked by converting the hyperlink's tag to a datarecord, then converting the dataitem of that datarecord into my object and checking it's id property.  I'm wondering if there isn't a more elegent way to go about this?

Parents
No Data
Reply
  • 69686
    Verified Answer
    posted

    The DataContext of the CVP is the DataRecord. You can use the DataItem property to bind to. You can as well create a binding like DataItem.NavigationURL if you have an underlying property for that. You can also bind to the Index of the record. The binding expression would depend on your data structure and what exactly you are trying to achieve.

Children