Serlialize succeseds only if the ContentTemplate manually set with Style and Setter tag in xaml

I followed the documentaion to complete the serlialize.I set a custom ContentTemplate for Node, but serlialize was unsuccessful after setting the ContentTemplate in the .cs file. The code is follow:

ContentTemplate = App.Current.Resources["myTemplate"] as DataTemplate

But if I set ContentTemplate use <Style> and <Setter> tags in xaml file, the serlialize is works well. The code is follow:

<Style TargetType="Syncfusion:Node">

                <Setter Property="ContentTemplate" Value="{StaticResource myTemplate}" />

</Style>



1 Reply

DT Deepa Thiruppathy Syncfusion Team March 24, 2022 02:17 PM UTC

Hi Tealer, 
 
Requirement: How to serialize the ContentTemplate of the Node directly. 
 
We do not serialize the ContentTemplate property by default, it can be achieved by deriving custom class for NodeViewModel. At the derived class, you can add a property to store the value of NodeViewModel ‘s Content or ContentTemplate property using ItemAddedEvent. And to serialize a new datatype, we need to add the new type in SfDiagram's KnownTypes.  
   
We have prepared simple sample for the same as below,   
  
 
Regards, 
Deepa Thiruppathy 
  
  


Loader.
Up arrow icon