I am trying to iterate layers and change visibility of fields in feature layers. I tryed to get "CIMFieldDescription" but it returns null when layer has default field descriptions.
Am I going in wrong way?
Solved! Go to Solution.
Hi
The best way to change the visibility of a field to use the IDisplayTable.
This code will set all the fields in a layer to be visible:
var table = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault() as IDisplayTable;
QueuedTask.Run( () => {
var fieldDescriptions = table.GetFieldDescriptions();
foreach (var field in fieldDescriptions)
{
field.IsVisible = true;
}
table.SetFieldDescriptions(fieldDescriptions);
});
Thanks
Uma
I used following code to change visibility but nothing changed on layers.
Map pmap = await FindOpenExistingMapAsync(tb_Map.Text);
List<BasicFeatureLayer> featureLayerList = pmap.GetLayersAsFlattenedList().OfType<BasicFeatureLayer>().ToList();
listView1.ItemsSource = pmap.GetLayersAsFlattenedList().OfType<BasicFeatureLayer>().ToList();
foreach (BasicFeatureLayer fl in featureLayerList)
{
await QueuedTask.Run(() =>
{
foreach (FieldDescription fd in fl.GetFieldDescriptions())
{
fd.IsVisible = true;
fd.Alias = myconfig.Alias;
}
});
}
Hi
The best way to change the visibility of a field to use the IDisplayTable.
This code will set all the fields in a layer to be visible:
var table = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault() as IDisplayTable;
QueuedTask.Run( () => {
var fieldDescriptions = table.GetFieldDescriptions();
foreach (var field in fieldDescriptions)
{
field.IsVisible = true;
}
table.SetFieldDescriptions(fieldDescriptions);
});
Thanks
Uma
Thank you for your help.
Your code help me to find out my mistake. My code worked by adding code "fl.SetFieldDescriptions(fieldDesc);"
Map pmap = await FindOpenExistingMapAsync(tb_Map.Text); List<BasicFeatureLayer> featureLayerList = pmap.GetLayersAsFlattenedList().OfType<BasicFeatureLayer>().ToList(); foreach (BasicFeatureLayer fl in featureLayerList) { await QueuedTask.Run(() => { var fieldDesc = fl.GetFieldDescriptions(); foreach (var fd in fieldDesc) { fd.IsVisible = myconfig.Visible; fd.Alias = myconfig.Alias; } fl.SetFieldDescriptions(fieldDesc); }); }