Hi Dominique, thank you!! With your advice, I am able to generate several different datagrids and show the identify results! I am really excited on this 😄 And I think your suggestion of generating datagrid by layer makes more sense since sometimes, the identify task may return more than one results from one layer. I think a little further based on your suggestion and I use a 2D graphic array to store the layerID and its graphics. Then I can assign them the graphic array or use the items inside it. So in the end I got this result [ATTACH]6683[/ATTACH] which is pretty what I want! 🙂 But I feel a little confused here regarding to the columns. I did set AutoGenerateColumns = false in the codes, but you can see that in this screenshot, the 1,2 and 4 layers have extra columns. I don't know why this happen and I am hopping they won't appear on the identifypage. The third datagrid seems good, in which it has a horizontal scrollbar and when I scroll to the end of the right side, there is no extra column.The second question I want to ask here is something related to overlapping. [ATTACH]6685[/ATTACH] The identifypage is beneath the layerlist (is constructed on a border). I think it may be due to floatable window's ParentLayoutRoot(idtask.ParentLayoutRoot)(I have changed the childwindow to floatable window since it won't block the interaction with parent window). I tried to change it to others but neither of them work 😞 Any suggestions or thought on how to make the datagrid on the most top?
else if (args.IdentifyResults.Count > 0)
{
_lastIdentifyResult = args.IdentifyResults;
Graphic[,] identifyList = new Graphic[34,30]; //declear a 2D graphic array to store the results, row: layerid (we have 34 layers in the map service), column: graphic
int [] gCount = new int [34]; //tract the number of graphics in each layer
idtask.IdentifyPanel.Children.Clear(); //clear the identify results datagrid
for (int i = 0; i < _lastIdentifyResult.Count; i++) //traversal each identify result
{
int layerIndex = _lastIdentifyResult.ElementAt(i).LayerId; //layerid of the result
gCount[layerIndex]++; //the number of the graphics in this layer plus one
Graphic identifyGraphic = _lastIdentifyResult.ElementAt(i).Feature; //graphic of the result
identifyList[layerIndex, (gCount[layerIndex]-1)] = identifyGraphic; //store the layerid and the graphic to the 2D graphic array
}
for (int i = 0; i < 34; i++ )
{
if (gCount > 0) //if the current layer has identify results, generate datagrid
{
List<Graphic> gList = new List<Graphic>(); //declar a new graphic list to store the graphics from the same layer
for (int k = 0; k < gCount; k++) //add the graphics to the graphic list
{
gList.Add(identifyList[i, k]);
}
TextBlock layernameTextBlc = new TextBlock();
layernameTextBlc.Text = dynamicServiceLayer.Layers.ElementAt(i).Name; //store the layer's name
TextBlock space = new TextBlock(); //a blank textblock used as a row space
space.Height = 10;
var idDataGrid = new DataGrid //generate a datagrid
{
Height = (gCount == 1? 50: 125),
AutoGenerateColumns = false,
IsReadOnly = true,
HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
VerticalScrollBarVisibility = ScrollBarVisibility.Visible,
HeadersVisibility = DataGridHeadersVisibility.Column,
Background = new SolidColorBrush(Colors.White),
RowStyle = (Style)LayoutRoot.Resources["MyCustomRow"],
CanUserSortColumns = true
};
idDataGrid.Columns.Clear();
//initialize a new attribute used for record index
int rec = 0;
foreach (var graphic in gList)
graphic.Attributes["Rec"] = ++rec;
//generate the first column for record index
DataGridTextColumn dataGridTextColumnRec = new DataGridTextColumn();
Binding Recbinder = new Binding();
Recbinder.Path = new PropertyPath("Attributes[Rec]");
dataGridTextColumnRec.Header = "Rec";
Recbinder.Mode = BindingMode.OneWay;
dataGridTextColumnRec.Binding = Recbinder;
idDataGrid.Columns.Add(dataGridTextColumnRec);
//generate the columns
for (int j = 0; j < identifyList[i, 0].Attributes.Count();j++ )
{
if (identifyList[i, 0].Attributes.ElementAt(j).Key == "Shape" || identifyList[i, 0].Attributes.ElementAt(j).Key == "Shape.area" ||
identifyList[i, 0].Attributes.ElementAt(j).Key == "Shape.len")
break;
DataGridTextColumn dataGridTextColumn = new DataGridTextColumn();
Binding binder = new Binding();
//binder.Path = new PropertyPath("Attributes[" + _lastIdentifyResult.ElementAt(i).Feature.Attributes.ElementAt(j).Key + "]");
binder.Path = new PropertyPath("Attributes[" + identifyList[i, 0].Attributes.ElementAt(j).Key + "]");
//dataGridTextColumn.Header = _lastIdentifyResult.ElementAt(i).Feature.Attributes.ElementAt(j).Key.ToString();
dataGridTextColumn.Header = identifyList[i, 0].Attributes.ElementAt(j).Key.ToString(); //header is the field alias
binder.Mode = BindingMode.OneWay;
dataGridTextColumn.Binding = binder;
idDataGrid.Columns.Add(dataGridTextColumn);
}
idDataGrid.ItemsSource = gList; //initialize the ItemsSource of the datagrid with that list of graphics
//idDataGrid.ItemsSource = new List<Graphic> { identifyList[i, 0] };
idtask.IdentifyPanel.Children.Add(space); //add the blank textblock
idtask.IdentifyPanel.Children.Add(layernameTextBlc); //add the layer's name
idtask.IdentifyPanel.Children.Add(idDataGrid); //add the datagrid
}
}
idtask.ParentLayoutRoot = InfoCanvas;
idtask.Show();
<Border x:Name="ResourceTabBorder" Margin="5,0,5,0" Visibility="Collapsed" BorderBrush="#FFFFFFCC">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="Visible Layers" Foreground="Black" FontWeight="Bold" Grid.Row="0"/>
<ListBox x:Name="ResourceListBox" FontSize="12" Background="#FFFFFFCC" BorderBrush="#FFFFFFCC" Grid.Row="1">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Margin="2" FontSize="9"
Name="ResourceCheckBox"
Content="{Binding Name}"
IsChecked="{Binding DefaultVisibility}"
Tag="{Binding ID}"
ClickMode="Press"
Click="ResourceCheckBox_Click"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Border>