How to replace part of ControlTemplate at runtime in Silverlight 3?

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.

+1
source share
1 answer

I guess I missed the obvious!

, OnApplyTemplate , VisualTreeHelper.GetChild(this, 0) , Children ( Panel-, , Canvas, Grid ..) // .

OnApplyTemplate, , VisualTreeHelper.GetChildrenCount 0.

+1

Source: https://habr.com/ru/post/1721593/


All Articles