Category / Section
How to serialize Content and ContentTemplate properties of a Node in WPF Diagram(SfDiagram)?
1 min read
In WPF Diagram (SfDiagram), we can’t directly serialize the Content and ContentTemplate properties of the Node. We must use custom properties to serialize them. We have prepared a simple sample to achieve how to serialize the Content and ContentTemplate properties of the Node.
XAML
CustomNode node1 = new CustomNode() { OffsetX = 150, OffsetY = 150, UnitHeight = 100, UnitWidth = 100, CustomContent = new NodeContent() { Content = "Node1" }, CustomContentTemplate = "NodeTemplate", }; (Nodes as NodeCollection).Add(node1); protected override void OnPropertyChanged(string name) { base.OnPropertyChanged(name); switch (name) { case "CustomContent": this.Content = this.CustomContent; break; case "CustomContentTemplate": this.ContentTemplate = App.Current.Resources[this.CustomContentTemplate] as DataTemplate; break; } }