예제 #1
0
        static DatePicker()
        {
            var gridFactory = new FrameworkElementFactory(typeof(Grid));
            var row0Factory = new FrameworkElementFactory(typeof(RowDefinition));

            row0Factory.SetValue(RowDefinition.HeightProperty, GridLength.Auto);
            gridFactory.AppendChild(row0Factory);

            var row1Factory = new FrameworkElementFactory(typeof(RowDefinition));

            row1Factory.SetValue(RowDefinition.HeightProperty, GridLength.Auto);
            gridFactory.AppendChild(row1Factory);

            var buttonFactory = new FrameworkElementFactory(typeof(Button))
            {
                Name = ElementButton
            };

            gridFactory.AppendChild(buttonFactory);

            var presenterFactory = new FrameworkElementFactory(typeof(ContentPresenter))
            {
                Name = ElementPresenter
            };

            presenterFactory.SetValue(Grid.RowProperty, 1);
            gridFactory.AppendChild(presenterFactory);

            DefaultTemplate = new ControlTemplate {
                VisualTree = gridFactory
            };
            DefaultTemplate.SetValue(ControlTemplate.TargetTypeProperty, typeof(DatePicker));
        }