I am writing a custom control that uses a template defined in the resource section of my XAML, and I would like to replace one or more parts of the template in an instance of my control at runtime.
For example, if I have a part called "ActivePart" in a control template, how do I replace the ActivePart FrameworkElement in the control instance with a new FrameworkElement?
I understand that the Control.Template property is writable, but I would prefer to find a way to replace a specific part of this template rather than create a completely new one, although a solution editing an existing template by replacing the corresponding named part would be acceptable.
I use C # and have to do this at runtime using any FrameworkElement element, so I am not looking for a XAML solution or suggestion, thanks!
PS I know that GetTemplateChild () returns a FrameworkElement for the named part of the template in the control instance, but I donโt see how this helps me replace this part with a new FrameworkElement.
source
share