Live Chat Icon For mobile
Live Chat Icon

How do I create a template programatically?

Platform: WPF| Category: Templates

You can create a template programatically by populating the VisualTree of the template.

[C#]
			DataTemplate template = new DataTemplate();

			template.VisualTree = new FrameworkElementFactory(typeof(Path));

			template.VisualTree.SetBinding(Path.StrokeProperty, new Binding('Stroke'));
			template.VisualTree.SetBinding(Path.StrokeThicknessProperty, new Binding('StrokeThickness'));
			template.VisualTree.SetBinding(Path.FillProperty, new Binding('Interior'));
			template.VisualTree.SetBinding(Path.DataProperty, new Binding('Geometry'));

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.