How to set Control Template in code?

Creating template in codebehind is not a good idea, in theory one would do this by defining the ControlTemplate.VisualTree which is a FrameworkElementFactory. ControlTemplate template = new ControlTemplate(typeof(Button)); var image = new FrameworkElementFactory(typeof(Image)); template.VisualTree = image; Assigning properties is very roundabout since you need to use SetValue and SetBinding: image.SetValue(Image.SourceProperty, …); Also, about the (previously) … Read more

What’s the difference between ContentControl and ContentPresenter?

ContentControl is a base class for controls that contain other elements and have a Content-property (for example, Button). ContentPresenter is used inside control templates to display content. ContentControl, when used directly (it’s supposed to be used as a base class), has a control template that uses ContentPresenter to display it’s content. My rules of thumb … Read more

tech