Id like to convert the contents of a cell to a hyperlink if the string value starts with "http". It has to work dynamically and alot of the example if found hard code the column value. Ideally i would like to just use value converter to replace the contents of a cell with a hyperlinkbutton if the content starts with "http".
<esri:FeatureDataGrid x:Name="QueryDetailsDataGrid" Grid.Row="0" Margin="0"
AutoGenerateColumns="False" CanUserSortColumns="True"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
HeadersVisibility="Column" HorizontalScrollBarVisibility="Auto"
SelectionChanged="QueryDetailsDataGrid_SelectionChanged"
LoadingRow="QueryDetailsDataGrid_LoadingRow"
Foreground="White" RowBackground="#555555"
AlternatingRowBackground="Black"
RowStyle="{StaticResource DataGridRowStyle}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click" SourceObject="{Binding ElementName=btnSave}">
<actions:ExportTable />
</i:EventTrigger>
</i:Interaction.Triggers>
<esri:FeatureDataGrid.Columns>
<sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding , Converter={StaticResource LinkConverter}}" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</esri:FeatureDataGrid.Columns>
</esri:FeatureDataGrid>
Converter
Public Class LinkConverter
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 Is Nothing Then
Return vbNull
Exit Function
End If
Dim _value As String = TryCast(value, String)
If _value Is Nothing Then
Return value
End If
If _value.StartsWith("http") Then
Dim hl As HyperlinkButton = New HyperlinkButton With {.NavigateUri = New Uri(_value)}
Return hl
Else
Return value
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 _value As String = TryCast(value, String)
If _value.StartsWith("http") Then
Dim hl As Hyperlink = New Hyperlink With {.NavigateUri = New Uri(_value)}
Return hl
Else
Return value
End If
End Function
End Class
This doesn't work because because im trying to replace the text with a framework element. Kinda stumped about how to do it this way....