I have a couple of map panes in ArcGIS Pro where the data source might differ from one occasion to te other. However, the name of the FeatureLayers are constant.
I am trying to adjust the underlaying data source based on user input. Meaning, the user has an OpenItemDialog listening on geodatabases. Plan is to use the retrieved path for the update.
However, I don't succeed.
In the following code snippet the selectedMapAjour is of type Map
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>selectedMapAjour <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN> <SPAN class="operator token">&&</SPAN> <SPAN class="operator token">!</SPAN><SPAN class="keyword token">string</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">IsNullOrEmpty</SPAN><SPAN class="punctuation token">(</SPAN>PathGdbAjour<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">foreach</SPAN> <SPAN class="punctuation token">(</SPAN>FeatureLayer layer <SPAN class="keyword token">in</SPAN> selectedMapAjour<SPAN class="punctuation token">.</SPAN>Layers<SPAN class="punctuation token">.</SPAN>OfType<SPAN class="operator token"><</SPAN>FeatureLayer<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="token function">GetSetDataConnection</SPAN><SPAN class="punctuation token">(</SPAN>layer<SPAN class="punctuation token">,</SPAN> PathGdbAjour<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">async</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">GetSetDataConnection</SPAN><SPAN class="punctuation token">(</SPAN>FeatureLayer layer<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">string</SPAN> newGDB<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">await</SPAN> QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN>
<SPAN class="punctuation token">{</SPAN>
CIMFeatureLayer def <SPAN class="operator token">=</SPAN> layer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetDefinition</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> CIMFeatureLayer<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> dcon <SPAN class="operator token">=</SPAN> def<SPAN class="punctuation token">.</SPAN>FeatureTable<SPAN class="punctuation token">.</SPAN>DataConnection <SPAN class="keyword token">as</SPAN> CIMStandardDataConnection<SPAN class="punctuation token">;</SPAN>
dcon<SPAN class="punctuation token">.</SPAN>WorkspaceConnectionString <SPAN class="operator token">=</SPAN> System<SPAN class="punctuation token">.</SPAN>IO<SPAN class="punctuation token">.</SPAN>Path<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Combine</SPAN><SPAN class="punctuation token">(</SPAN>newGDB<SPAN class="punctuation token">,</SPAN> layer<SPAN class="punctuation token">.</SPAN>Name<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
layer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetDefinition</SPAN><SPAN class="punctuation token">(</SPAN>def<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>The code runs through... only the exclamation mark in the TOC of the map do not disappear. Although, the path set via dcon.WorkspaceConnectionString is reflected in the properties of the FeatureLayers in the TOC.
Hence, I am not sure if my attempt to alter the data source worked and I am missing some refresh or update call, or if this does not work at all.
I basically need a C# equivalent of updateConnectionProperties.
Thereafter, I will have to adjust the symbology, so ApplySymbologyFromLayer would be next. 
Does anybody has an example for this stuff?
Best Thomas