tags:

views:

267

answers:

1

I have a Custom Control which uses some PART controls:

 [TemplatePart(Name = "PART_TitleTextBox", Type = typeof(TextBox))]
    [TemplatePart(Name = "PART_TitleIndexText", Type = typeof(Label))]
    [TemplatePart(Name = "PART_TimeCodeInText", Type = typeof(TextBlock))]
    [TemplatePart(Name = "PART_TimeCodeOutText", Type = typeof(TextBlock))]
    [TemplatePart(Name = "PART_ApprovedImage", Type = typeof(Image))]
    [TemplatePart(Name = "PART_CommentsImage", Type = typeof(Image))]
    [TemplatePart(Name = "PART_BookmarkedImage", Type = typeof(Image))]
    public class TitleBoxNew : Control
    {

This control is overriding OnApplyTemplate:

public override void OnApplyTemplate()
{
      base.OnApplyTemplate();

      InitializeEvents();
}

Which works well, most of the time. I have added the control inside a custom tab control in a window and somehow OnApplyTemplate is never called for that control! Why doesn't this work as I expect?

+1  A: 

I can't see your constructor, but don't forget to set the DefaultStyleKey:

DefaultStyleKeyProperty.OverrideMetadata(typeof(TitleBoxNew), new FrameworkPropertyMetadata(typeof(TitleBoxNew)));
mattdekrey
Yes i frogot to mention that, i already got this:static TitleBoxNew() { DefaultStyleKeyProperty.OverrideMetadata(typeof(TitleBoxNew), new FrameworkPropertyMetadata(typeof(TitleBoxNew))); } public TitleBoxNew() { }
Lasse O
Nice wrapping stackoverflow, well done
Lasse O
Please edit your orignal post to contain your constructor; comments aren't the correct spot for code.
mattdekrey
Nice question, Lasse O, well done. What about offending Mark Byers as a next step for [editing your original post](http://stackoverflow.com/posts/2939787/revisions)?!
gehho