//Hyperlink private void IdentifyDetailsDataGrid_LoadingRow(object sender, DataGridRowEventArgs e) { try { string s = e.Row.DataContext.ToString(); //Check for the field name "Website". if (s.Contains("Website")) { string[] sSplit = s.Split(','); string[] link = sSplit[1].Split(']'); DataGridColumn column = this.IdentifyDetailsDataGrid.Columns[1]; FrameworkElement fe = column.GetCellContent(e.Row); FrameworkElement result = GetParent(fe, typeof(DataGridCell)); if (result != null) { DataGridCell cell = (DataGridCell)result; //Set the URL to empty sring if found a null value. //if (String.IsNullOrEmpty(link[0].Trim())) if (link[0].Trim() == "Null" || link[0] == null) link[0] = String.Empty; cell.Content = new URLField() { url = link[0] }; DataTemplate dt = this.Resources["HyperlinkButtonTemplate"] as DataTemplate; cell.ContentTemplate = dt; } } } catch { } } private FrameworkElement GetParent(FrameworkElement child, Type targetType) { object parent = child.Parent; if (parent != null) { if (parent.GetType() == targetType) { return (FrameworkElement)parent; } else { return GetParent((FrameworkElement)parent, targetType); } } return null; } } public class URLField { public string url { get; set; } }
public void ShowFeatures(List<IdentifyResult> results) { _dataItems = new List<DataItem>(); if (results != null && results.Count > 0) { 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 }); var fieldsToDisplay = new List<string>() { "School Name", "Address", "Zip", "Phone", "Website", "School District" }; var attributesToDisplay = new Dictionary<string, object>(); foreach (var item in feature.Attributes) if (fieldsToDisplay.Contains(item.Key)) attributesToDisplay[item.Key] = item.Value; if (result.LayerId == 4) IdentifyDetailsDataGrid.ItemsSource = feature.Attributes; IdentifyDetailsDataGrid.ItemsSource = attributesToDisplay; if (result.LayerId == 9) IdentifyDetailsDataGrid2.ItemsSource = feature.Attributes; IdentifyDetailsDataGrid2.ItemsSource = attributesToDisplay; if (result.LayerId == 14) IdentifyDetailsDataGrid3.ItemsSource = feature.Attributes; IdentifyDetailsDataGrid3.ItemsSource = attributesToDisplay; }
Solved! Go to Solution.
private void IdentifyDetailsDataGrid_LoadingRow(object sender, DataGridRowEventArgs e) { try { string s = e.Row.DataContext.ToString(); if (s.Contains("http")) { string[] sSplit = s.Split(','); string[] link = sSplit[1].Split(']'); DataGridColumn column = this.IdentifyDetailsDataGrid.Columns[1]; FrameworkElement fe = column.GetCellContent(e.Row); FrameworkElement result = GetParent(fe, typeof(DataGridCell)); if (result != null) { DataGridCell cell = (DataGridCell)result; if (link[0].Trim() == "Null" || link[0] == null) link[0] = String.Empty; cell.Content = new URLField() { url = link[0] }; DataTemplate dt = this.Resources["HyperlinkButtonTemplate"] as DataTemplate; cell.ContentTemplate = dt; } } } catch { } } private FrameworkElement GetParent(FrameworkElement child, Type targetType) { object parent = child.Parent; if (parent != null) { if (parent.GetType() == targetType) { return (FrameworkElement)parent; } else { return GetParent((FrameworkElement)parent, targetType); } } return null; } } public class URLField { public string url { get; set; } }
<DataTemplate x:Key="HyperlinkButtonTemplate"> <HyperlinkButton x:Name="hl" Margin="5" TargetName="_blank" Content="{Binding url}" NavigateUri="{Binding url}"/> </DataTemplate>
<StackPanel x:Name="IdentifyResultsStackPanel" Margin="15,30,15,10" Visibility="Collapsed"> <TextBlock Text="ELEMENTARY SCHOOL ATTENDANCE AREA:" Foreground="White" FontSize="14" FontStyle="Italic" Margin="0,0,0,5" /> <slData:DataGrid x:Name="IdentifyDetailsDataGrid" AutoGenerateColumns="False" LoadingRow="IdentifyDetailsDataGrid_LoadingRow" HeadersVisibility="None" > <slData:DataGrid.Columns> <slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/> <slData:DataGridTextColumn Binding="{Binding Path=Value}"/> </slData:DataGrid.Columns> </slData:DataGrid> <TextBlock Text="MIDDLE SCHOOL ATTENDANCE AREA:" Foreground="White" FontSize="14" FontStyle="Italic" Margin="0,0,0,5" /> <slData:DataGrid x:Name="IdentifyDetailsDataGrid2" AutoGenerateColumns="False" LoadingRow="IdentifyDetailsDataGrid_LoadingRow" HeadersVisibility="None" > <slData:DataGrid.Columns> <slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/> <slData:DataGridTextColumn Binding="{Binding Path=Value}"/> </slData:DataGrid.Columns> </slData:DataGrid> <TextBlock Text="HIGH SCHOOL ATTENDANCE AREA:" Foreground="White" FontSize="14" FontStyle="Italic" Margin="0,0,0,5" /> <slData:DataGrid x:Name="IdentifyDetailsDataGrid3" AutoGenerateColumns="False" LoadingRow="IdentifyDetailsDataGrid_LoadingRow" HeadersVisibility="None" > <slData:DataGrid.Columns> <slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/> <slData:DataGridTextColumn Binding="{Binding Path=Value}"/> </slData:DataGrid.Columns> </slData:DataGrid> </StackPanel>
private void IdentifyDetailsDataGrid_LoadingRow(object sender, DataGridRowEventArgs e) { try { string s = e.Row.DataContext.ToString(); if (s.Contains("http")) { string[] sSplit = s.Split(','); string[] link = sSplit[1].Split(']'); //Begin problem code DataGridColumn column = this.IdentifyDetailsDataGrid.Columns[1]; //You need to write something like //DataGridColumn column = this.string //{ foreach DataGrid.IdentifyDetailsDataGrid // DataGrid.IdentifyDetailsDataGrid1 // DataGrid.IdentifyDetailsDataGrid2 // } FrameworkElement fe = column.GetCellContent(e.Row); FrameworkElement result = GetParent(fe, typeof(DataGridCell)); if (result != null) { DataGridCell cell = (DataGridCell)result; if (link[0].Trim() == "Null" || link[0] == null) link[0] = String.Empty; cell.Content = new URLField() { url = link[0] }; DataTemplate dt = this.Resources["HyperlinkButtonTemplate"] as DataTemplate; cell.ContentTemplate = dt; } } } catch { } }
private void IdentifyDetailsDataGrid_LoadingRow2(object sender, DataGridRowEventArgs e) { try { string s = e.Row.DataContext.ToString(); if (s.Contains("http")) { string[] sSplit = s.Split(','); string[] link = sSplit[1].Split(']'); DataGridColumn column = this.IdentifyDetailsDataGrid2.Columns[1]; FrameworkElement fe = column.GetCellContent(e.Row); FrameworkElement result = GetParent(fe, typeof(DataGridCell)); if (result != null) { DataGridCell cell = (DataGridCell)result; if (link[0].Trim() == "Null" || link[0] == null) link[0] = String.Empty; cell.Content = new URLField() { url = link[0] }; DataTemplate dt = this.Resources["HyperlinkButtonTemplate"] as DataTemplate; cell.ContentTemplate = dt; } } } catch { } } private void IdentifyDetailsDataGrid_LoadingRow3(object sender, DataGridRowEventArgs e) { try { string s = e.Row.DataContext.ToString(); if (s.Contains("http")) { string[] sSplit = s.Split(','); string[] link = sSplit[1].Split(']'); DataGridColumn column = this.IdentifyDetailsDataGrid3.Columns[1]; FrameworkElement fe = column.GetCellContent(e.Row); FrameworkElement result = GetParent(fe, typeof(DataGridCell)); if (result != null) { DataGridCell cell = (DataGridCell)result; if (link[0].Trim() == "Null" || link[0] == null) link[0] = String.Empty; cell.Content = new URLField() { url = link[0] }; DataTemplate dt = this.Resources["HyperlinkButtonTemplate"] as DataTemplate; cell.ContentTemplate = dt; } } } catch { } }
<slData:DataGrid x:Name="IdentifyDetailsDataGrid2" AutoGenerateColumns="False" LoadingRow="IdentifyDetailsDataGrid_LoadingRow" HeadersVisibility="None" > and <slData:DataGrid x:Name="IdentifyDetailsDataGrid3" AutoGenerateColumns="False" LoadingRow="IdentifyDetailsDataGrid_LoadingRow" HeadersVisibility="None" >
<slData:DataGrid x:Name="IdentifyDetailsDataGrid2" AutoGenerateColumns="False" LoadingRow="IdentifyDetailsDataGrid_LoadingRow2" HeadersVisibility="None" > and <slData:DataGrid x:Name="IdentifyDetailsDataGrid3" AutoGenerateColumns="False" LoadingRow="IdentifyDetailsDataGrid_LoadingRow3" HeadersVisibility="None" >