如果字符串值以“http”开头,我想将单元格的内容转换为超链接。如果发现对列值进行硬编码,它必须动态工作并且有很多示例。理想情况下,如果内容以“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>
转换器
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
这不起作用,因为我试图用框架元素替换文本。有点困惑如何做到这一点......