<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: UIElement in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/uielement/m-p/1085540#M10332</link>
    <description>&lt;P&gt;It sounds like it might represent a form of symbol to style a graphic in a graphics overlay?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could use RenderTagetBitmap to render an image and apply that via a PictureMarkerSymbol.&lt;/P&gt;&lt;P&gt;Here's some code that creates a UniqueValueRenderer from a series of UIElements rendered using RenderTargetBitmap:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private async Task CreatePictureMarkerSymbols()
{
	_strobeCanvas = new Canvas();
	Ellipse ellipse = new Ellipse()
	{
		Height = 40,
		Width = 40,
		IsHitTestVisible = false,
		RenderTransform = new ScaleTransform(),
		Fill = new RadialGradientBrush()
		{
			GradientStops = new GradientStopCollection(5)
			{
				new GradientStop(Color.FromArgb(0,255, 0, 0),0),
				new GradientStop(Color.FromArgb(255,255, 0, 0),0.25),
				new GradientStop(Color.FromArgb(0,255, 0, 0),0.5),
				new GradientStop(Color.FromArgb(255,255, 0, 0),0.75),
				new GradientStop(Color.FromArgb(0,255, 0, 0),1),
			}
		}
	};
	_strobeCanvas.Children.Add(ellipse);

	for (int i = 1; i &amp;lt;= _numberOfPictureMarkerSymbols; i++)
	{
		// Scale up the Ellipse
		double increment = Convert.ToDouble(i) / 5;
		Transform scaleTransform = new ScaleTransform(increment, increment);
		double scaleTransformOrigin = 0;

		ellipse.Opacity -= _opacityStep;
		ellipse.RenderTransform = scaleTransform;
		ellipse.RenderTransformOrigin = new Point(scaleTransformOrigin, scaleTransformOrigin);

		_strobeCanvas.RenderTransform = scaleTransform;
		_strobeCanvas.RenderTransformOrigin = new Point(scaleTransformOrigin, scaleTransformOrigin);
		_strobeCanvas.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
		_strobeCanvas.Arrange(new Rect(ellipse.DesiredSize));
		Rect bounds = VisualTreeHelper.GetContentBounds(ellipse);
		bounds.Transform(ellipse.RenderTransform.Value);

		var dpiXProperty = typeof(SystemParameters).GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static);
		var dpiX = (int)dpiXProperty.GetValue(null, null);
		double dpi = Convert.ToDouble(dpiX);

		// Create a new RenderTargetBitmap to render the ellipse
		RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(
						(Int32)(bounds.Width * dpi / 96.0),
						(Int32)(bounds.Height * dpi / 96.0),
						dpi,
						dpi,
						PixelFormats.Pbgra32);

		// Setup the drawing context
		DrawingVisual drawingVisual = new DrawingVisual();
		using (DrawingContext drawingContext = drawingVisual.RenderOpen())
		{
			VisualBrush visualBrush = new VisualBrush(ellipse);
			drawingContext.DrawRectangle(visualBrush, pen: null, rectangle: new Rect(new Point(), bounds.Size));
		}

		// Render the visual element
		renderTargetBitmap.Render(drawingVisual);

		// Use a PngBitmapEncoder to retrieve the image 
		PngBitmapEncoder pngBitmapEncoder = new PngBitmapEncoder();
		pngBitmapEncoder.Frames.Add(BitmapFrame.Create(source: renderTargetBitmap));

		using (var stream = new MemoryStream())
		{
			pngBitmapEncoder.Save(stream);
			stream.Seek(0, SeekOrigin.Begin);

			// Create a new PictureMarkerSymbol and set the Source
			PictureMarkerSymbol pms = await PictureMarkerSymbol.CreateAsync(stream);


			// Create a new UniqueValueInfo class for this image instance
			UniqueValue strobeUniqueValueInfo = new UniqueValue()
			{
				Symbol = pms,
			};

			// Add the UniqueValueInfo to the UniqueValueRenderer
			strobeUniqueValueInfo.Values.Add(i);
			_strobeUniqueValueRenderer.UniqueValues.Add(strobeUniqueValueInfo);
		}
	}
	// Set the UniqueValueRenderer field
	_strobeUniqueValueRenderer.FieldNames.Add(_strobeField);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternatively, if it's one or more symbols defined in XAML and you are looking for a longer term solution and vectorized rendering then you could look into converting the XAML to SVG and importing the SVG into ArcGIS Pro as a symbol layer for a mobile style which you can use in ArcGIS Runtime.&lt;/P&gt;&lt;P&gt;Resources:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Read symbols from a mobile style:&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/wpf/sample-code/read-symbols-from-mobile-style/" target="_blank"&gt;https://developers.arcgis.com/net/wpf/sample-code/read-symbols-from-mobile-style/&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;Symbol editor demo showcasing mobile style and multi layer symbol editing:&amp;nbsp;&amp;nbsp;&lt;A href="https://github.com/Esri/arcgis-runtime-demos-dotnet/tree/main/src/SymbolEditor" target="_blank"&gt;https://github.com/Esri/arcgis-runtime-demos-dotnet/tree/main/src/SymbolEditor&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
    <pubDate>Tue, 03 Aug 2021 22:33:27 GMT</pubDate>
    <dc:creator>MichaelBranscomb</dc:creator>
    <dc:date>2021-08-03T22:33:27Z</dc:date>
    <item>
      <title>UIElement</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/uielement/m-p/1085496#M10329</link>
      <description>&lt;P&gt;Is it possible to display a WPF UIElement as a graphic overlay onto an Arcgis basemap?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Aug 2021 20:50:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/uielement/m-p/1085496#M10329</guid>
      <dc:creator>johnmarker</dc:creator>
      <dc:date>2021-08-03T20:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: UIElement</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/uielement/m-p/1085540#M10332</link>
      <description>&lt;P&gt;It sounds like it might represent a form of symbol to style a graphic in a graphics overlay?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could use RenderTagetBitmap to render an image and apply that via a PictureMarkerSymbol.&lt;/P&gt;&lt;P&gt;Here's some code that creates a UniqueValueRenderer from a series of UIElements rendered using RenderTargetBitmap:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private async Task CreatePictureMarkerSymbols()
{
	_strobeCanvas = new Canvas();
	Ellipse ellipse = new Ellipse()
	{
		Height = 40,
		Width = 40,
		IsHitTestVisible = false,
		RenderTransform = new ScaleTransform(),
		Fill = new RadialGradientBrush()
		{
			GradientStops = new GradientStopCollection(5)
			{
				new GradientStop(Color.FromArgb(0,255, 0, 0),0),
				new GradientStop(Color.FromArgb(255,255, 0, 0),0.25),
				new GradientStop(Color.FromArgb(0,255, 0, 0),0.5),
				new GradientStop(Color.FromArgb(255,255, 0, 0),0.75),
				new GradientStop(Color.FromArgb(0,255, 0, 0),1),
			}
		}
	};
	_strobeCanvas.Children.Add(ellipse);

	for (int i = 1; i &amp;lt;= _numberOfPictureMarkerSymbols; i++)
	{
		// Scale up the Ellipse
		double increment = Convert.ToDouble(i) / 5;
		Transform scaleTransform = new ScaleTransform(increment, increment);
		double scaleTransformOrigin = 0;

		ellipse.Opacity -= _opacityStep;
		ellipse.RenderTransform = scaleTransform;
		ellipse.RenderTransformOrigin = new Point(scaleTransformOrigin, scaleTransformOrigin);

		_strobeCanvas.RenderTransform = scaleTransform;
		_strobeCanvas.RenderTransformOrigin = new Point(scaleTransformOrigin, scaleTransformOrigin);
		_strobeCanvas.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
		_strobeCanvas.Arrange(new Rect(ellipse.DesiredSize));
		Rect bounds = VisualTreeHelper.GetContentBounds(ellipse);
		bounds.Transform(ellipse.RenderTransform.Value);

		var dpiXProperty = typeof(SystemParameters).GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static);
		var dpiX = (int)dpiXProperty.GetValue(null, null);
		double dpi = Convert.ToDouble(dpiX);

		// Create a new RenderTargetBitmap to render the ellipse
		RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(
						(Int32)(bounds.Width * dpi / 96.0),
						(Int32)(bounds.Height * dpi / 96.0),
						dpi,
						dpi,
						PixelFormats.Pbgra32);

		// Setup the drawing context
		DrawingVisual drawingVisual = new DrawingVisual();
		using (DrawingContext drawingContext = drawingVisual.RenderOpen())
		{
			VisualBrush visualBrush = new VisualBrush(ellipse);
			drawingContext.DrawRectangle(visualBrush, pen: null, rectangle: new Rect(new Point(), bounds.Size));
		}

		// Render the visual element
		renderTargetBitmap.Render(drawingVisual);

		// Use a PngBitmapEncoder to retrieve the image 
		PngBitmapEncoder pngBitmapEncoder = new PngBitmapEncoder();
		pngBitmapEncoder.Frames.Add(BitmapFrame.Create(source: renderTargetBitmap));

		using (var stream = new MemoryStream())
		{
			pngBitmapEncoder.Save(stream);
			stream.Seek(0, SeekOrigin.Begin);

			// Create a new PictureMarkerSymbol and set the Source
			PictureMarkerSymbol pms = await PictureMarkerSymbol.CreateAsync(stream);


			// Create a new UniqueValueInfo class for this image instance
			UniqueValue strobeUniqueValueInfo = new UniqueValue()
			{
				Symbol = pms,
			};

			// Add the UniqueValueInfo to the UniqueValueRenderer
			strobeUniqueValueInfo.Values.Add(i);
			_strobeUniqueValueRenderer.UniqueValues.Add(strobeUniqueValueInfo);
		}
	}
	// Set the UniqueValueRenderer field
	_strobeUniqueValueRenderer.FieldNames.Add(_strobeField);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternatively, if it's one or more symbols defined in XAML and you are looking for a longer term solution and vectorized rendering then you could look into converting the XAML to SVG and importing the SVG into ArcGIS Pro as a symbol layer for a mobile style which you can use in ArcGIS Runtime.&lt;/P&gt;&lt;P&gt;Resources:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Read symbols from a mobile style:&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/wpf/sample-code/read-symbols-from-mobile-style/" target="_blank"&gt;https://developers.arcgis.com/net/wpf/sample-code/read-symbols-from-mobile-style/&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;Symbol editor demo showcasing mobile style and multi layer symbol editing:&amp;nbsp;&amp;nbsp;&lt;A href="https://github.com/Esri/arcgis-runtime-demos-dotnet/tree/main/src/SymbolEditor" target="_blank"&gt;https://github.com/Esri/arcgis-runtime-demos-dotnet/tree/main/src/SymbolEditor&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Tue, 03 Aug 2021 22:33:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/uielement/m-p/1085540#M10332</guid>
      <dc:creator>MichaelBranscomb</dc:creator>
      <dc:date>2021-08-03T22:33:27Z</dc:date>
    </item>
  </channel>
</rss>

