using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace DependencyPropertyExample
{
    // Example 18-19. Connecting with named parts

    [TemplatePart(Name = "PART_Body", Type = typeof(ContentControl))]
    [TemplatePart(Name = "PART_Fuse", Type = typeof(FrameworkElement))]
    public class ControlWithNamedParts : Control
    {
        ContentControl body;
        FrameworkElement fuse;

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

            body = Template.FindName("PART_Body", this) as ContentControl;
            fuse = Template.FindName("PART_Fuse", this) as FrameworkElement;
        }

        static ControlWithNamedParts()
        {
            //This OverrideMetadata call tells the system that this element wants to provide a style that is different than its base class.
            //This style is defined in themes\generic.xaml
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ControlWithNamedParts), new FrameworkPropertyMetadata(typeof(ControlWithNamedParts)));
        }

    }

    // End of Example 18-19.
}
