I'm having some difficulty using the AddAttributeAsync() method on the Inspector class. I have tried with different sets of attributes but I can never get the embeddable control to render the fields I have added, it only renders when I have loaded a full layer schema or a mapmember and objectId.
Could anyone provide a sample that shows proper usage of this method? I was presuming it is this call that would provide for displaying a subset of attributes for modification much like the Create Feature experience shows. I didn't see any usage of this method in the community samples projects.
Solved! Go to Solution.
We are working on a sample to help explain use, in the meantime I believe I can give you a couple hints...
We always use this with a new (empty) inspector created with isFeatureEdiitng = false and if you call Load or LoadSchema on it after adding fields it would just overwrite the fields you have added so just add the fields you want explicitly.
After setting up the inspector we usually are done Adding more fields by the time we create the EmbeddableControl and show it on the UI. Adding after the view is being shown should work but is not currently utilized, so may be buggy.
You will then need to read whatever values out of the Inspector and do whatever you want with them at some point.
Tasks and Parcels use this internally and Create features uses a variant of it (but since it has access to internal methods it uses some features not exposed publicly).
Here's a sample that illustrates how to use the AddAttributeAsync method. It contains a single tool which displays a grid requesting attribute values from the user. After entering values into the grid, the user is required to sketch a rectangle to identify features. The attributes entered will then be applied to the features identified.
A couple of things to note.
The sample is written to work in conjunction with the 'Interacting With Maps.aprx' from the Community Samples Data. It works specifically with the Police Stations layer in that project.
In the sample I have added 2 attributes from a single layer into the inspector. However, there is no reason why you cannot have multiple attributes from multiple layers in the inspector at one time. It just depends on your purpose. As an example, Create Features only works with attributes from a single layer, whereas Tasks (in the GetAttributes action) allows attributes from multiple layers to be in the inspector grid at one time.
The sample also illustrates the validation of the attributes via the Attribute.AddValidate routine. This is how the red border outline appears. Obviously if no errors are returned, (or no Validation occurs) the attribute is deemed to be valid.
Let us know if you have any further questions or if you have trouble accessing this zip / sample. You may need to re-reference the ArcGIS dlls in the project according to your install location.
I will also get this posted to the Pro SDK Community Samples github repository.