Display CIM symbol JSON in .NET ComboBox

1005
2
Jump to solution
12-09-2020 01:46 PM
Douglas_DMeredith
New Contributor II

Is there a way to display CIMSymbol, or the raw JSON, as an image in a .NET ComboBox? Or is there a way to export that JSON to a PNG or other image file?

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Douglas, 

 The upcoming 2.7 release has a symbol picker control as part of the SDK.   The symbol picker displays a 'preview' image of the symbol in a listbox (just like Pro does).   Regarding your question: you have a CIMSymbol and want to either display a 'preview image' for that symbol or extract the JSON to display the JSON string?  We have a sample here:  arcgis-pro-sdk-community-samples/Map-Authoring/CustomSymbolPicker at master · Esri/arcgis-pro-sdk-co... that might provide some inside, but if you can describe your desired workflow in more detail i can probably guide you in the right direction.

View solution in original post

2 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Douglas, 

 The upcoming 2.7 release has a symbol picker control as part of the SDK.   The symbol picker displays a 'preview' image of the symbol in a listbox (just like Pro does).   Regarding your question: you have a CIMSymbol and want to either display a 'preview image' for that symbol or extract the JSON to display the JSON string?  We have a sample here:  arcgis-pro-sdk-community-samples/Map-Authoring/CustomSymbolPicker at master · Esri/arcgis-pro-sdk-co... that might provide some inside, but if you can describe your desired workflow in more detail i can probably guide you in the right direction.

Douglas_DMeredith
New Contributor II

That sample helped a lot. SymbolStyleItem has the magic sauce I was looking for. My CIM symbol JSON is kept in a table. Walking the table, I now do this:

 

CF cf = new CF();
cf.key = row["key"].ToString();
cf.symbol = row["symbol"].ToString();
//Wrap the symbol JSON in CIMSymbolReference, so we can use that class to 
//deserialize it.
cf.symbol = cf.symbol.Insert(0, "{\"type\": \"CIMSymbolReference\", \"symbol\": ");
cf.symbol = cf.symbol.Insert(cf.symbol.Length, "}");

//Create the preview image used in the ComboBox
SymbolStyleItem sSI = new SymbolStyleItem() {
	Symbol = CIMSymbolReference.FromJson(cf.symbol).Symbol,
	PatchWidth = 16,
	PatchHeight = 16
};
cf.preview = sSI.PreviewImage;

 

 

And the xaml for the ComboBox now looks like this:

 

<ComboBox 
		x:Name="ContactsAndFaultsComboBox" 
		IsTextSearchEnabled="True"
		TextSearch.TextPath="key"
		ItemsSource="{Binding Path=(ui:DataHelper.CFs)}" 
		SelectedItem ="{Binding SelectedCF}" 
		Margin="0,0,0,5"  
		IsReadOnly="False" 
		IsEditable="True"  
		HorizontalAlignment="Left" 
		Height="25"  
		VerticalAlignment="Top" 
		Width="200">
	<ComboBox.ItemTemplate>
		<DataTemplate>
			<StackPanel Orientation="Horizontal">
				<Image Source="{Binding preview}"  Margin="0,2,5,2" />
				<TextBlock Text="{Binding key}" />
			</StackPanel>
		</DataTemplate>
	</ComboBox.ItemTemplate>
</ComboBox>

 


Thanks, Wolf!