Hi Wolfgang,
Please note some strange behaviors related to the title of the popup:
Firstly, the dialog Pop-up / Title Options has no save option/button. Not sure, but I feel that it is saving only when exiting ArgGis Pro 1.3.
Then: when not involved any code, maybe related to having same layer names from different geodatabases: the pop-up window will get the title specks from the first layer in the Contents disregarding the layer the feature belong to.
When using custom code: there is no option to specify a Title on custom content, but this time, the title comes from the second layer in the content (Or the standard one: the one showing the layer name and the object ID, though the object Id comes as <null>,) again disregarding the layer the feature which generates the custom content comes from!
And this is my code inherited from Community Samples:
(Sorry the Advance Editor is making a mess from this document on formatting as C#!)
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
using GFXModule.Properties;
namespace GFXModule
{
/// <summary>
/// Implementation of custom pop-up tool.
/// </summary>
internal class PickupTool : MapTool
{
/// <summary>
/// Define the tool as a sketch tool that draws a rectangle in screen space on the view.
/// </summary>
public PickupTool()
{
IsSketchTool = true;
switch(Settings.Default.GfxPickOption)
{
case PickToolOptions.Point:
SketchType = SketchGeometryType.Point;
Cursor = GetCursor("PointCursor.cur");
break;
case PickToolOptions.Rectangle:
SketchType = SketchGeometryType.Rectangle;
Cursor = GetCursor("RectangleCursor.cur");
break;
case PickToolOptions.Circle:
SketchType = SketchGeometryType.Circle;
Cursor = GetCursor("CircleCursor.cur");
break;
}
UseSnapping = true;
//Cursor = Cursors.Arrow;
SketchOutputMode = SketchOutputMode.Screen; //required for 3D selection and identify.
}
private static Cursor GetCursor(string imagesCursorCur)
{
try
{
var streamResourceInfo = Application.GetResourceStream(new Uri(@"pack://application:,,,/GFXModule;component/Images/"+imagesCursorCur));
if (streamResourceInfo != null)
return new Cursor(
streamResourceInfo.Stream
);
}
catch (IOException)
{
}
catch (UriFormatException)
{
}
return Cursors.Cross;
}
/// <summary>
/// Called when a sketch is completed.
/// </summary>
protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
if (Module1.GfxViewModel == null) return false;
var popupContent = await QueuedTask.Run(() =>
{
var mapView = MapView.Active;
if (mapView == null)
return null;
//Get the features that intersect the sketch geometry.
var result = mapView.GetFeatures(geometry);
//For each feature in the result create a new instance of our custom popup content class.
List<PopupContent> popups = new List<PopupContent>();
foreach (var kvp in result)
{
kvp.Value.ForEach(id => popups.Add(new GfxPopupContent(kvp.Key, id, kvp.Key == Module1.GfxViewModel.DeltaLayer)));
}
//Flash the features that intersected the sketch geometry.
mapView.FlashFeature(result);
//return the collection of popup content object.
return popups;
});
//Show the custom pop-up with the custom commands and the default pop-up commands.
MapView.Active.ShowCustomPopup(popupContent, CreateCommands(), true);
return true;
}
/// <summary>
/// Create and return a new collection of popup commands
/// </summary>
/// <returns></returns>
private List<PopupCommand> CreateCommands()
{
var commands = new List<PopupCommand>
{
new PopupCommand(OnPopupCommand, CanExecutePopupCommand,
"Pair this",
new BitmapImage(new Uri("pack://application:,,,/GFXModule;component/Images/Pickup16.png")))
{
IsSeparator = true
}
};
//Add a new instance of a popup command passing in the delegate to be run when the button is clicked.
return commands;
}
/// <summary>
/// The method called when the custom popup command is clicked.
/// </summary>
void OnPopupCommand(PopupContent content)
{
//Cast the content parameter to our custom popup content class.
var dynamicContent = content as GfxPopupContent;
//Call a method on the custom popup content object to show some statistics for the current popup content.
dynamicContent?.PairFeature();
}
/// <summary>
/// The method called periodically by the framework to determine if the command should be enabled.
/// </summary>
bool CanExecutePopupCommand(PopupContent content)
{
return
content != null
&& content.MapMember.Map.Name.StartsWith("Delta Map");
}
}
}
(I should add the code for GfxPopupContent, but I dare not!)