<sdk:DataGridTemplateColumn Header="Code" Width="40">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<HyperlinkButton IsHitTestVisible="{Binding Path=MyUrl,
Converter={StaticResource InvertNullOrEmptyConverter}}"
Content="{Binding Code}" NavigateUri="{Binding MyUrl}"/>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn><ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
Width="330" MinHeight="200" Grid.Row="1">
<slData:DataGrid x:Name="IdentifyDetailDataGrid" AutoGenerateColumns="False" HeadersVisibility="None"
Background="White">
<slData:DataGrid.Columns>
<slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>
<slData:DataGridTextColumn Binding="{Binding Path=Value}"/>
</slData:DataGrid.Columns>
</slData:DataGrid>
</ScrollViewer><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:YourNamespaceHere"> <Style TargetType="local:LinkLabel"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="local:LinkLabel"> <StackPanel Margin="2,0,2,0" VerticalAlignment="Center"> <TextBlock x:Name="LabelText" Visibility="Collapsed" /> <HyperlinkButton x:Name="LinkText" Visibility="Collapsed" /> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary>
[TemplatePart(Name = "LabelText", Type = typeof(TextBlock)),
TemplatePart(Name = "LinkText", Type = typeof(HyperlinkButton))]
public class LinkLabel : Control
{
private TextBlock _labelText;
private HyperlinkButton _linkText;
private const string Pattern = @"\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]";
public LinkLabel()
{
DefaultStyleKey = typeof(LinkLabel);
}
public string TextValue
{
get { return (string)GetValue(TextValueProperty); }
set { SetValue(TextValueProperty, value); }
}
public static readonly DependencyProperty TextValueProperty =
DependencyProperty.Register("TextValue", typeof(string), typeof(LinkLabel), new PropertyMetadata(string.Empty, TextValuePropertyChanged));
private static void TextValuePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
var linkLabel = sender as LinkLabel;
if (linkLabel != null) linkLabel.Refresh();
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_labelText = (TextBlock)GetTemplateChild("LabelText");
_linkText = (HyperlinkButton)GetTemplateChild("LinkText");
Refresh();
}
public void Refresh()
{
if (_labelText == null || _linkText == null)
return;
var regex = new Regex(Pattern);
if (string.IsNullOrWhiteSpace(TextValue) || !regex.IsMatch(TextValue))
{
_labelText.Text = TextValue;
_labelText.Visibility = Visibility.Visible;
_linkText.Visibility = Visibility.Collapsed;
}
else
{
_linkText.Content = TextValue;
_linkText.NavigateUri = new Uri(TextValue, UriKind.RelativeOrAbsolute);
_labelText.Visibility = Visibility.Collapsed;
_linkText.Visibility = Visibility.Visible;
}
}
}
<ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto" Width="230" MinHeight="200" Grid.Row="1">
<sdk:DataGrid x:Name="IdentifyDetailsDataGrid" AutoGenerateColumns="False" HeadersVisibility="None" background="White">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Binding="{Binding Key}" FontWeight="Bold" />
<sdk:DataGridTextColumn Binding="{Binding Value}" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
</ScrollViewer>
public void ShowFeatures(List<IdentifyResult> results)
{
_dataItems = new List<DataItem>();
if (results != null && results.Count > 0)
{
IdentifyComboBox.Items.Clear();
foreach (IdentifyResult result in results)
{
Graphic feature = result.Feature;
string title = result.Value.ToString() + " (" + result.LayerName + ")";
_dataItems.Add(new DataItem()
{
Title = title,
Data = feature.Attributes
});
IdentifyComboBox.Items.Add(title);
}
IdentifyComboBox.SelectedIndex = 0;
}
}ShowFeatures(args.IdentifyResults);
<slData:DataGrid.Columns>
<slData:DataGridTextColumn Binding="{Binding Path=Key}" />
<slData:DataGridTemplateColumn>
<slData:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<localControls:LinkLabel TextValue="{Binding Path=Value}" />
</DataTemplate>
</slData:DataGridTemplateColumn.CellTemplate>
</slData:DataGridTemplateColumn>
</slData:DataGrid.Columns>