예제 #1
0
파일: ListBox.cs 프로젝트: qcjxberin/MPF
        static ListBox()
        {
            ListBox.ItemContainerGeneratorActivatorProperty.OverrideMetadata(typeof(ListBox),
                                                                             new PropertyMetadata <Func <ItemsControl, ItemContainerGenerator> >(l => new ListBoxItemContainerGenerator((ListBox)l)));
            ListBox.StyleProperty.OverrideMetadata(typeof(ListBox), new FrameworkPropertyMetadata <Style>(
                                                       new Style(typeof(ListBox))
                                                       .SetLocalValue(ListBox.TemplateProperty, ControlTemplate.Create <ListBox>(t =>
            {
                var itemsHost = new ItemsPresenter();
                BindingOperations.SetBinding(itemsHost, ItemsPresenter.ItemsSourceProperty, new Binding {
                    Path = "ItemsSource", Source = t
                });
                BindingOperations.SetBinding(itemsHost, ItemsPresenter.ItemContainerGeneratorProperty, new Binding {
                    Path = "ItemContainerGenerator", Source = t
                });
                BindingOperations.SetBinding(itemsHost, ItemsPresenter.ItemsPanelTemplateProperty, new Binding {
                    Path = "ItemsPanelTemplate", Source = t
                });

                var root = new Border
                {
                    Child = itemsHost
                };

                return(root);
            }))));
        }