OnApplyTemplate not called in Custom Control

Posted by Lasse O on Stack Overflow See other posts from Stack Overflow or by Lasse O
Published on 2010-05-30T18:23:44Z Indexed on 2010/05/30 18:32 UTC
Read the original article Hit count: 1758

Filed under:

I am SICK AND TIRED of WPF and all its "if thats dosen't work, try this" fucking fixes ALL THE TIME, well heres one the collection:

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 IS WPF SO FUCKING RANDOM!?

© Stack Overflow or respective owner

Related posts about wpf