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?
Using the sample code above I cannot get the hyperlinks to work, here's my snippet. The code compiles and I can run my app but the byperlinks do not appear. Maybe I'm missing something else???
<igDP:XamDataGrid Height="Auto" Name="xamDataGridWebLinks" Width="Auto" DataSource="{Binding}" Background="Transparent" Foreground="White" > <igDP:XamDataGrid.Resources> <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> </igDP:XamDataGrid.Resources> </igDP:XamDataGrid>
Thanks, Troy
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.