@PreetiMaske is correct although I have found it a tad more complex and it depends what you mean by palette, and what you are doing it in. If your in WPF it is pretty straight forward because WPF does not have things going on behind the scenes to optimize.
The basic approach is to create a Model that expose an ImageSource which can be bound to your palette in the DataTemplate. The ViewModel would contain the ObservableCollection of that Model. Which is bound to the list being used to display the palette.
Then you have to get the ImageSource. Something along these lines. When the Model object is created the RuntimeImage is converted to an ImageSource. Having a .Wait() in the constructor is certainly not a best practice, but it is how I implemented. Using something like a static CreateAsync on the Model object is probably a better pattern
//this is the model - the item of the collection being bound
public class SymbolItem
public SymbolItem(LegendInfo legendInfo, ...)
{
LegendInfo = legendInfo;
...
Task t = Task.Run(InitializeAsync);
t.Wait();
}
private async Task InitializeAsync()
{
//A little unclear on best way to adjust the parameters to get the image to size best
RuntimeImage runtimeImage;
if ( FeatureTable.GeometryType == GeometryType.Polyline )
{
runtimeImage = await LegendInfo.Symbol.CreateSwatchAsync(24, 24, 128f, Color.Transparent, new Polyline(new [] {new MapPoint(-10, 0), new MapPoint(10, 0) }));
}
else
{
runtimeImage = await LegendInfo.Symbol.CreateSwatchAsync(24, 24, 128f, Color.Transparent, new MapPoint(0, 0));
}
ImageSource source = await runtimeImage.ToImageSourceAsync();
//http://stackoverflow.com/questions/26361020/error-must-create-dependencysource-on-same-thread-as-the-dependencyobject-even
source.Freeze();
Dispatcher.CurrentDispatcher.Invoke(() => ImageSource = source);
}
public ImageSource ImageSource { get; set; }
...
}
In my ViewModel there is the ObservableCollection of these
public ObservableCollection<SymbolItem> SymbolItems { get; set; } = new ObservableCollection<SymbolItem>();
In Xaml I bind to the ImageSource
<!-- Would be nice to use this control, but have no control over image size with it -->
<!--<esritoolkit:SymbolDisplay Symbol="{Binding LegendInfo.Symbol, Mode=OneTime}" Margin="0,0,5,0" />-->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="{Binding ImageSource}" />
</Grid>
As noted there, the esri toolkit does have a SymbolItem but at least in 100.6 I found it did not provide enough control over sizing.
In Xamarin Forms you have an added complexity in how it recycles images. That required creating custom ViewCells to handle this issue... I won't go into that at this time
Thanks,
-Joe