Get ContentControl Control Template Children?

We are working on a Silverlight application that uses a common custom ContentControl. This ContentControl has the control template specified in Generic.xaml.

Inherited ContentControl Template ...

<Style TargetType="local:ExtContentControl"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="local:ExtContentControl"> <Border x:Name="content" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Child="{TemplateBinding Content}"> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> 

Inherited ComboBox template ...

 <controltemplate targettype="local:ExtComboBox"></controltemplate> 

...

 <Rectangle x:Name="FocusVisualElement" IsHitTestVisible="false" Margin="1" Opacity="0" RadiusY="2" RadiusX="2" Stroke="#FF6DBDD1" StrokeThickness="1"/> 

When you create an instance of the ContentControl content, a (generic) control is installed, which can be a text, drop-down, shortcut, or Datepicker.

 public class ExtContentControl : ContentControl { public ExtContentControl() { this.DefaultStyleKey = typeof(ExtContentControl); RenderControl(); } private void RenderControl() { ExtComboBox extComboBox = new ExtComboBox(); this.Content = extComboBox; } public override void OnApplyTemplate() { base.OnApplyTemplate(); Border bor = GetTemplateChild("content") as Border; ExtComboBox cmbTest = bor.Child as ExtComboBox; //Find FocusVisualElement from ExtComboBox Control Template //Rectangle rec = cmbTest.FindName("FocusVisualElement") as Rectangle; //cmbTest returns null } } 

As you can see in my last comment ...

// Find FocusVisualElement from the ExtComboBox control template // Rectangle rec = cmbTest.FindName ("FocusVisualElement") as a Rectangle; // cmbTest returns null

How can I get a FocusVisualElement from inside an OnApplyTemplate inside a ContentControl?

Hope this makes sense.

+4
source share

All Articles