예제 #1
0
        void InitGrid_1()
        {
            TreeView treevue = new TreeView();

            this.grid1.Children.Add(treevue);

            HierarchicalDataTemplate template = new HierarchicalDataTemplate(typeof(DiskDirectory));

            template.ItemsSource = new Binding(nameof(DiskDirectory.SubDirectories));

            FrameworkElementFactory factoryTextBlock = new FrameworkElementFactory(typeof(TextBlock));

            factoryTextBlock.SetBinding(TextBlock.TextProperty, new Binding(nameof(DiskDirectory.Name)));

            template.VisualTree = factoryTextBlock;

            DiskDirectory dir = new DiskDirectory(new DirectoryInfo(Path.GetPathRoot(Environment.SystemDirectory)));

            TreeViewItem item = new TreeViewItem();

            item.Header       = dir.Name;
            item.ItemsSource  = dir.SubDirectories;
            item.ItemTemplate = template;

            treevue.Items.Add(item);
            item.IsExpanded = true;
        }
예제 #2
0
        public TemplateTheTree()
        {
            Title = "Template the Tree";

            TreeView tree = new TreeView();

            Content = tree;

            HierarchicalDataTemplate template = new HierarchicalDataTemplate(typeof(DiskDirectory));

            template.ItemsSource = new Binding("Subdirectories");

            FrameworkElementFactory factoryTextBlock = new FrameworkElementFactory(typeof(TextBlock));

            factoryTextBlock.SetBinding(TextBlock.TextProperty, new Binding("Name"));

            template.VisualTree = factoryTextBlock;

            DiskDirectory dir  = new DiskDirectory(new DirectoryInfo(Path.GetPathRoot(Environment.SystemDirectory)));
            TreeViewItem  item = new TreeViewItem();

            item.Header       = dir.Name;
            item.ItemsSource  = dir.Subdirectories;
            item.ItemTemplate = template;

            tree.Items.Add(item);
            item.IsExpanded = true;
        }
예제 #3
0
        public void ApplyBinding()
        {
            object dataContext = base.DataContext;

            if (dataContext != null)
            {
                DataTemplate         dataTemplate           = this.HeaderTemplate;
                DataTemplateSelector headerTemplateSelector = this.HeaderTemplateSelector;
                if (headerTemplateSelector != null)
                {
                    dataTemplate = headerTemplateSelector.SelectTemplate(dataContext, this);
                }
                if (dataTemplate == null)
                {
                    DataTemplateKey resourceKey = BreadcrumbItem.GetResourceKey(dataContext);
                    if (resourceKey != null)
                    {
                        dataTemplate = (base.TryFindResource(resourceKey) as DataTemplate);
                    }
                }
                this.SelectedItem = null;
                HierarchicalDataTemplate hierarchicalDataTemplate = dataTemplate as HierarchicalDataTemplate;
                if (dataTemplate != null)
                {
                    this.Header = dataTemplate.LoadContent();
                }
                else
                {
                    this.Header = dataContext;
                }
                this.DataContext = dataContext;
                if (hierarchicalDataTemplate != null)
                {
                    this.SetBinding(ItemsControl.ItemsSourceProperty, hierarchicalDataTemplate.ItemsSource);
                }
                BreadcrumbBar breadcrumbBar = this.BreadcrumbBar;
                if (breadcrumbBar != null)
                {
                    if (this.TraceBinding == null)
                    {
                        this.TraceBinding = breadcrumbBar.TraceBinding;
                    }
                    if (this.ImageBinding == null)
                    {
                        this.ImageBinding = breadcrumbBar.ImageBinding;
                    }
                }
                if (this.TraceBinding != null)
                {
                    this.SetBinding(BreadcrumbItem.TraceProperty, this.TraceBinding);
                }
                if (this.ImageBinding != null)
                {
                    this.SetBinding(BreadcrumbItem.ImageProperty, this.ImageBinding);
                }
                this.ApplyProperties(dataContext);
            }
        }
예제 #4
0
        private static DataTemplate CreateArchiveListingTemplate(bool hierarchical)
        {
            DataTemplate template;

            if (hierarchical)
            {
                //template = new HierarchicalDataTemplate {DataType = typeof(UiArchiveNodeOld)};
                //((HierarchicalDataTemplate)template).ItemsSource = new Binding("OrderedHierarchyChilds");
                template = new HierarchicalDataTemplate {
                    DataType = typeof(UiContainerNode)
                };
                ((HierarchicalDataTemplate)template).ItemsSource = new Binding("BindableHierarchyChilds");
            }
            else
            {
                //template = new DataTemplate {DataType = typeof(UiArchiveNodeOld)};
                template = new DataTemplate {
                    DataType = typeof(UiNode)
                };
            }

            FrameworkElementFactory stackPanel = new FrameworkElementFactory(typeof(StackPanel));

            stackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);

            FrameworkElementFactory checkbox = new FrameworkElementFactory(typeof(CheckBox));

            checkbox.SetValue(ToggleButton.IsCheckedProperty, new Binding("IsChecked")
            {
                Mode = BindingMode.TwoWay
            });
            checkbox.SetValue(ToggleButton.IsThreeStateProperty, true);
            stackPanel.AppendChild(checkbox);

            FrameworkElementFactory image = new FrameworkElementFactory(typeof(Image));

            image.SetValue(HeightProperty, 16d);
            image.SetValue(Image.SourceProperty, new Binding("Icon"));
            image.SetValue(MarginProperty, new Thickness(3));
            stackPanel.AppendChild(image);

            //FrameworkElementFactory icon = new FrameworkElementFactory(typeof(ContentPresenter));
            //icon.SetValue(ContentPresenter.ContentProperty, new Binding("Icon"));
            //icon.SetValue(MarginProperty, new Thickness(3));
            //stackPanel.AppendChild(icon);

            FrameworkElementFactory textBlock = new FrameworkElementFactory(typeof(TextBlock));

            textBlock.SetBinding(TextBlock.TextProperty, new Binding("Name"));
            textBlock.SetValue(MarginProperty, new Thickness(3));
            stackPanel.AppendChild(textBlock);

            template.VisualTree = stackPanel;

            return(template);
        }
예제 #5
0
        /// <summary>
        /// Initialise le DataTemplate
        /// </summary>
        protected virtual void InitializeDataTemplate()
        {
            HierarchicalDataTemplate dataTemplate = new HierarchicalDataTemplate(typeof(PeriodName));

            dataTemplate.ItemsSource = new Binding("childrenListChangeHandler.Items");
            FrameworkElementFactory factory = new FrameworkElementFactory(typeof(TextBlock));

            factory.SetBinding(TextBlock.TextProperty, new Binding("name"));
            dataTemplate.VisualTree = factory;
        }
예제 #6
0
        private void AttachItemTemplate()
        {
            var template = new HierarchicalDataTemplate(typeof(TreeNodeBase))
            {
                ItemsSource = new Binding(nameof(TreeNodeBase.Children)),
                VisualTree  = GetItemTemplateFactory(),
            };

            template.Seal();
            AssociatedObject.ItemTemplate = template;
        }
예제 #7
0
        /// <summary>
        /// 构造一个带复选框的TreeView控件
        /// </summary>
        public CheckableTree()
        {
            mResouce.Source = new Uri("VCCustomControls;component/CheckableTree.xaml", UriKind.Relative);
            Resources.MergedDictionaries.Add(mResouce);
            HierarchicalDataTemplate itemDataTemplate = (HierarchicalDataTemplate)mResouce["CheckBoxItemTemplate"];
            Style itemStyle = (Style)mResouce["TreeViewItemStyle"];

            ItemTemplate       = itemDataTemplate;
            ItemContainerStyle = itemStyle;
            mIsShowIcon        = false;
        }
        /// <summary>
        /// Set Template for Selected TreeViewItem
        /// </summary>
        /// <param name="templateName">Template Name</param>
        private void SetTemplateForSelectedItem(String templateName)
        {
            HierarchicalDataTemplate hdt = (HierarchicalDataTemplate)Resources[templateName];

            TreeViewItem selectedTreeViewItem =
                TreeViewExtensions.GetContainerFromItem(TreeViewMain, selectedNode);

            if (selectedTreeViewItem != null)
            {
                selectedTreeViewItem.HeaderTemplate = hdt;
            }
        }
 private void ChMaster_Checked(object sender, RoutedEventArgs e)
 {
     try
     {
         HierarchicalDataTemplate h = new HierarchicalDataTemplate();
         TreeViewItem             t = new TreeViewItem();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #10
0
        /// <summary>
        /// Initialise le DataTemplate
        /// </summary>
        protected virtual void InitializeDataTemplate()
        {
            HierarchicalDataTemplate dataTemplate = new HierarchicalDataTemplate(typeof(Misp.Kernel.Domain.Measure));

            dataTemplate.ItemsSource = new Binding("childrenListChangeHandler.Items");

            FrameworkElementFactory factory = new FrameworkElementFactory(typeof(TextBlock));

            factory.SetBinding(TextBlock.TextProperty, new Binding("name"));

            dataTemplate.VisualTree = factory;
            //this.tree.ItemTemplate = dataTemplate;
        }
예제 #11
0
        private bool _SearchUpToWindow(Type key, out HierarchicalDataTemplate template)
        {
            FrameworkElement currentHost = this;

            while (currentHost != null)
            {
                if (_SearchDictionary(currentHost.Resources, key, out template))
                {
                    return(true);
                }
                currentHost = currentHost.Parent as FrameworkElement;
            }
            template = null;
            return(false);
        }
예제 #12
0
            private DataTemplate CreateDataTemplate()
            {
                HierarchicalDataTemplate template = new HierarchicalDataTemplate
                {
                    ItemsSource = new Binding("BindableChilds")
                };

                FrameworkElementFactory textBlock = new FrameworkElementFactory(typeof(TextBlock));

                textBlock.SetBinding(TextBlock.TextProperty, new Binding("Title"));
                textBlock.SetBinding(ContextMenuProperty, new Binding("BindableContextMenu"));

                template.VisualTree = textBlock;
                return(template);
            }
예제 #13
0
        /// <summary>
        /// Initialise le DataTemplate
        /// </summary>
        protected virtual void InitializeDataTemplate()
        {
            HierarchicalDataTemplate dataTemplate = new HierarchicalDataTemplate(GetDataType());

            dataTemplate.ItemsSource = new Binding(GetChildrenBindingName());

            FrameworkElementFactory factory = new FrameworkElementFactory(GetRendererDataType());

            factory.SetBinding(EditableTextBlock.TextProperty, new Binding(GetRendererBindingName()));

            dataTemplate.VisualTree = factory;

            HierarchicalDataTemplate template = System.Windows.Application.Current.Resources["EditableTreeViewTemplate"] as HierarchicalDataTemplate;

            this.ItemTemplate = template;
        }
        private HierarchicalDataTemplate GenerateHierarchicalDataTemplate()
        {
            HierarchicalDataTemplate dataTemplate = new HierarchicalDataTemplate(typeof(ExplorerItem));

            string hierarchicalItemsSource = "Items"; // Explorer Items property

            dataTemplate.ItemsSource = new Binding(hierarchicalItemsSource);

            string hierarchicalMemberPath = "Header"; // Explorer Header property
            FrameworkElementFactory frameworkElementFactory = new FrameworkElementFactory(typeof(ContentPresenter));

            frameworkElementFactory.SetBinding(ContentPresenter.ContentProperty, new Binding(hierarchicalMemberPath));
            dataTemplate.VisualTree = frameworkElementFactory;

            return(dataTemplate);
        }
예제 #15
0
        private HierarchicalDataTemplate GetTemplate()
        {
            //create the data template
            HierarchicalDataTemplate dataTemplate = new HierarchicalDataTemplate();

            //create stack pane;
            FrameworkElementFactory grid = new FrameworkElementFactory(typeof(Grid));

            grid.Name = "parentStackpanel";
            grid.SetValue(Grid.WidthProperty, Convert.ToDouble(200));
            grid.SetValue(Grid.HeightProperty, Convert.ToDouble(24));
            grid.SetValue(Grid.MarginProperty, new Thickness(2));

            // Create Image
            FrameworkElementFactory image = new FrameworkElementFactory(typeof(Image));

            image.SetValue(Image.MarginProperty, new Thickness(2));
            image.SetValue(Image.VerticalAlignmentProperty, VerticalAlignment.Center);
            image.SetValue(Image.HorizontalAlignmentProperty, HorizontalAlignment.Left);
            image.SetBinding(Image.SourceProperty, new Binding()
            {
                Path = new PropertyPath("ImageUrl")
            });

            grid.AppendChild(image);

            // create text
            FrameworkElementFactory label = new FrameworkElementFactory(typeof(TextBlock));

            label.SetBinding(TextBlock.TextProperty,
                             new Binding()
            {
                Path = new PropertyPath("Title")
            });
            label.SetValue(TextBlock.MarginProperty, new Thickness(25, 2, 2, 2));
            label.SetValue(TextBlock.FontWeightProperty, FontWeights.Bold);
            label.SetValue(TextBlock.ToolTipProperty, new Binding("Title"));

            grid.AppendChild(label);

            dataTemplate.ItemsSource = new Binding("Items");

            //set the visual tree of the data template
            dataTemplate.VisualTree = grid;

            return(dataTemplate);
        }
        private HierarchicalDataTemplate GenerateHierarchicalDataTemplateWithImage()
        {
            HierarchicalDataTemplate dataTemplate = new HierarchicalDataTemplate(typeof(ExplorerItem));

            string hierarchicalItemsSource = "Items";     // Explorer Items property
            string hierarchicalMemberPath  = "Header";    // Explorer Header property
            string hierarchicalImagePath   = "ImagePath"; // Explorer ImagePath property

            dataTemplate.ItemsSource = new Binding(hierarchicalItemsSource);

            FrameworkElementFactory frameworkElementFactory = new FrameworkElementFactory(typeof(Grid));

            var column1 = new FrameworkElementFactory(typeof(ColumnDefinition));

            column1.SetValue(ColumnDefinition.WidthProperty, GridLength.Auto);

            var column2 = new FrameworkElementFactory(typeof(ColumnDefinition));

            column2.SetValue(ColumnDefinition.WidthProperty, new GridLength(1, GridUnitType.Star));

            frameworkElementFactory.AppendChild(column1);
            frameworkElementFactory.AppendChild(column2);

            var image = new FrameworkElementFactory(typeof(Image));

            image.SetValue(Image.SourceProperty, new Binding(hierarchicalImagePath));
            image.SetValue(Image.MaxHeightProperty, 16.0);
            image.SetValue(Image.MaxWidthProperty, 16.0);
            image.SetValue(Image.HorizontalAlignmentProperty, HorizontalAlignment.Center);
            image.SetValue(Image.MarginProperty, new Thickness(3, 0, 3, 0));

            var textBlock = new FrameworkElementFactory(typeof(TextBlock));

            textBlock.SetValue(TextBlock.TextProperty, new Binding(hierarchicalMemberPath));
            textBlock.SetValue(Grid.ColumnProperty, 1);

            frameworkElementFactory.AppendChild(image);
            frameworkElementFactory.AppendChild(textBlock);

            dataTemplate.VisualTree = frameworkElementFactory;

            return(dataTemplate);
        }
예제 #17
0
        public TemplateTheTree()
        {
            Title = "Template the Tree";

            // Create TreeView and set as content of window.
            TreeView treevue = new TreeView();

            Content = treevue;

            // Create HierarchicalDataTemplate based on DiskDirectory.
            HierarchicalDataTemplate template =
                new HierarchicalDataTemplate(typeof(DiskDirectory));

            // Set Subdirectories property as ItemsSource.
            template.ItemsSource = new Binding("Subdirectories");

            // Create FrameworkElementFactory for TextBlock.
            FrameworkElementFactory factoryTextBlock =
                new FrameworkElementFactory(typeof(TextBlock));

            // Bind Text property with Name property from DiskDirectory.
            factoryTextBlock.SetBinding(TextBlock.TextProperty,
                                        new Binding("Name"));

            // Set this Textblock as the VisualTree of the template.
            template.VisualTree = factoryTextBlock;

            // Create a DiskDirectory object for the system drive.
            DiskDirectory dir = new DiskDirectory(
                new DirectoryInfo(
                    Path.GetPathRoot(Environment.SystemDirectory)));

            // Create a root TreeViewItem and set its properties.
            TreeViewItem item = new TreeViewItem();

            item.Header       = dir.Name;
            item.ItemsSource  = dir.Subdirectories;
            item.ItemTemplate = template;

            // Add TreeViewItem to TreeView.
            treevue.Items.Add(item);
            item.IsExpanded = true;
        }
        private HierarchicalDataTemplate CreateTemplate(Type t)
        {
            string image;

            if (t == typeof(DatabaseExplorerServerViewModel))
            {
                image = "server";
            }
            else if (t == typeof(DatabaseExplorerDatabaseViewModel))
            {
                image = "database";
            }
            else
            {
                image = "table";
            }


            var dt = new HierarchicalDataTemplate(t);

            dt.ItemsSource = new Binding("Children");
            var f = new FrameworkElementFactory(typeof(StackPanel));

            f.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
            var fi = new FrameworkElementFactory(typeof(Image));

            fi.SetValue(Image.SourceProperty,
                        new BitmapImage(new Uri(@"pack://application:,,,/MongoMS;component/View/" + image + ".png")));
            var ft = new FrameworkElementFactory(typeof(TextBlock));

            ft.SetBinding(TextBlock.TextProperty, new Binding("Name"));
            f.AppendChild(fi);
            f.AppendChild(ft);
            ContextMenu menu = GetMenu(t);

            f.SetValue(FrameworkElement.ContextMenuProperty, menu);
            var fcc = new FrameworkElementFactory(typeof(ContentControl));

            fcc.AddHandler(Control.MouseDoubleClickEvent, new MouseButtonEventHandler(tb_MouseUp));
            fcc.AppendChild(f);
            dt.VisualTree = fcc;
            return(dt);
        }
예제 #19
0
        /// <summary>
        /// When data template changes, get the new 'ItemsSource' as the property name for child items
        /// </summary>
        /// <param name="oldItemTemplate">the old data template</param>
        /// <param name="newItemTemplate">the new data template</param>
        protected override void OnItemTemplateChanged(DataTemplate oldItemTemplate, DataTemplate newItemTemplate)
        {
            base.OnItemTemplateChanged(oldItemTemplate, newItemTemplate);

            HierarchicalDataTemplate itemTemplate = this.ItemTemplate as HierarchicalDataTemplate;

            this.childCollectionPropertyName = null;
            this.childCollectionPropertyInfo = null;

            if (itemTemplate != null)
            {
                Binding childBinding = itemTemplate.ItemsSource as Binding;
                if (childBinding != null && childBinding.Path != null)
                {
                    // only support simple property path here, other parameters ignored
                    this.childCollectionPropertyName = childBinding.Path.Path;
                }
            }
        }
예제 #20
0
        public DrawTaskTree(Grid grid, Project project)
        {
            treeView = new TreeView();
            HierarchicalDataTemplate hdt       = new HierarchicalDataTemplate();
            FrameworkElementFactory  textBlock = new FrameworkElementFactory(typeof(TextBlock));

            textBlock.SetBinding(TextBlock.TextProperty, new Binding("TaskName"));
            hdt.ItemsSource = new Binding("Children");
            drawCM          = new DrawContextMenu();
            textBlock.SetValue(TextBlock.ContextMenuProperty, drawCM.contextMenuForTasks);
            hdt.VisualTree        = textBlock;
            treeView.ItemTemplate = hdt;
            treeView.ItemsSource  = project.Root;

            Thickness margin = treeView.Margin;

            margin.Top      = 10;
            margin.Right    = 1000;
            margin.Bottom   = 10;
            treeView.Margin = margin;

            CreateTaskTree(grid);
        }
예제 #21
0
        private void SetContextMenu()
        {
            HierarchicalDataTemplate _hdtTerritories = new HierarchicalDataTemplate();

            _hdtTerritories.DataType = typeof(Territory);
            HierarchicalDataTemplate _hdtTeams = new HierarchicalDataTemplate();

            _hdtTeams.DataType = typeof(Team);
            FrameworkElementFactory _TeamFactory = new FrameworkElementFactory(typeof(TreeViewItem));

            _TeamFactory.Name = "txtTeamInfo";
            _TeamFactory.SetBinding(TreeViewItem.HeaderProperty, new Binding("TeamProperty1"));
            FrameworkElementFactory _TerritoryFactory = new FrameworkElementFactory(typeof(TreeViewItem));

            _TerritoryFactory.Name = "txtTerritoryInfo";
            _TerritoryFactory.SetBinding(TreeViewItem.HeaderProperty, new Binding("TerritoryProperty1"));

            _hdtTeams.ItemsSource          = new Binding("Territories");
            _hdtTeams.VisualTree           = _TeamFactory;
            _hdtTerritories.VisualTree     = _TerritoryFactory;
            _hdtTeams.ItemTemplate         = _hdtTerritories;
            _TeritorySwitcher.ItemTemplate = _hdtTeams;
            _TeritorySwitcher.ItemsSource  = this._Teams;
        }
예제 #22
0
        /// <summary>
        ///  Appies the binding to the breadcrumb item.
        /// </summary>
        public void ApplyBinding()
        {
            object item = DataContext;

            if (item == null)
            {
                return;
            }

            BreadcrumbItem       root             = this;
            DataTemplate         template         = HeaderTemplate;
            DataTemplateSelector templateSelector = HeaderTemplateSelector;

            if (templateSelector != null)
            {
                template = templateSelector.SelectTemplate(item, root);
            }
            if (template == null)
            {
                DataTemplateKey key = GetResourceKey(item);
                if (key != null)
                {
                    template = TryFindResource(key) as DataTemplate;
                }
            }

            root.SelectedItem = null;

            HierarchicalDataTemplate hdt = template as HierarchicalDataTemplate;

            if (template != null)
            {
                root.Header = template.LoadContent();
            }
            else
            {
                root.Header = item;
            }
            root.DataContext = item;

            if (hdt != null)
            {
                // bind the Items to the hierarchical data template:
                root.SetBinding(BreadcrumbItem.ItemsSourceProperty, hdt.ItemsSource);
            }

            BreadcrumbBar bar = BreadcrumbBar;

            if (bar != null)
            {
                if (TraceBinding == null)
                {
                    TraceBinding = bar.TraceBinding;
                }
                if (ImageBinding == null)
                {
                    ImageBinding = bar.ImageBinding;
                }
            }

            if (TraceBinding != null)
            {
                root.SetBinding(BreadcrumbItem.TraceProperty, TraceBinding);
            }
            if (ImageBinding != null)
            {
                root.SetBinding(BreadcrumbItem.ImageProperty, ImageBinding);
            }


            ApplyProperties(item);
        }
예제 #23
0
        private HierarchicalDataTemplate setUpTheHierarchy()
        {
            //Class Topic_Keywords
            FrameworkElementFactory ft = new FrameworkElementFactory(typeof(StackPanel));

            ft.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);

            FrameworkElementFactory im = new FrameworkElementFactory(typeof(Image));

            im.SetValue(Image.SourceProperty, findImageSource("../../img/icons/folder-icon-16x16.png"));
            im.SetValue(Image.WidthProperty, Double.Parse("14"));
            im.SetValue(Image.HeightProperty, Double.Parse("14"));
            im.SetValue(Image.MarginProperty, new Thickness(4, 0, 0, 0));
            ft.AppendChild(im);

            FrameworkElementFactory tb = new FrameworkElementFactory(typeof(TextBlock));

            tb.SetBinding(TextBlock.TextProperty, new Binding("Date"));
            tb.SetValue(TextBlock.MarginProperty, new Thickness(4, 0, 0, 0));

            ft.AppendChild(tb);

            HierarchicalDataTemplate t = new HierarchicalDataTemplate(typeof(Topic_Keyword));

            t.ItemsSource = new Binding("Items");
            t.VisualTree  = ft;


            //Class Keywords

            FrameworkElementFactory ff = new FrameworkElementFactory(typeof(StackPanel));

            ff.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);

            FrameworkElementFactory ima = new FrameworkElementFactory(typeof(Image));

            ima.SetValue(Image.SourceProperty, findImageSource("../../img/icons/feed-icon-14x14.png"));
            ima.SetValue(Image.WidthProperty, Double.Parse("14"));
            ima.SetValue(Image.HeightProperty, Double.Parse("14"));
            ima.SetValue(Image.MarginProperty, new Thickness(4, 0, 0, 0));
            ff.AppendChild(ima);

            FrameworkElementFactory tbt = new FrameworkElementFactory(typeof(TextBlock));

            tbt.SetBinding(TextBlock.TextProperty, new Binding("Text"));
            //tbt.SetBinding(TextBlock, new Binding() { RelativeSource= RelativeSource.Self });
            tbt.SetValue(TextBlock.MarginProperty, new Thickness(4, 0, 0, 0));
            ff.AppendChild(tbt);



            FrameworkElementFactory f = new FrameworkElementFactory(typeof(CheckBox));

            f.SetBinding(CheckBox.ClickModeProperty, new Binding("ThreeWay"));
            f.SetBinding(CheckBox.DataContextProperty, new Binding());
            f.AppendChild(ff);
            f.AddHandler(CheckBox.CheckedEvent, new RoutedEventHandler(isChecked));
            f.AddHandler(CheckBox.UncheckedEvent, new RoutedEventHandler(isUnchecked));


            HierarchicalDataTemplate tmp = new HierarchicalDataTemplate(typeof(Keyword));

            tmp.ItemsSource = new Binding("Items");

            tmp.VisualTree = f;

            t.ItemTemplate = tmp;

            return(t);
        }
        // Token: 0x06004E5D RID: 20061 RVA: 0x00160980 File Offset: 0x0015EB80
        private void PrepareHierarchy(object item, ItemsControl parentItemsControl)
        {
            DataTemplate dataTemplate = this.HeaderTemplate;

            if (dataTemplate == null)
            {
                DataTemplateSelector headerTemplateSelector = this.HeaderTemplateSelector;
                if (headerTemplateSelector != null)
                {
                    dataTemplate = headerTemplateSelector.SelectTemplate(item, this);
                }
                if (dataTemplate == null)
                {
                    dataTemplate = (DataTemplate)FrameworkElement.FindTemplateResourceInternal(this, item, typeof(DataTemplate));
                }
            }
            HierarchicalDataTemplate hierarchicalDataTemplate = dataTemplate as HierarchicalDataTemplate;

            if (hierarchicalDataTemplate != null)
            {
                bool flag  = base.ItemTemplate == parentItemsControl.ItemTemplate;
                bool flag2 = base.ItemContainerStyle == parentItemsControl.ItemContainerStyle;
                if (hierarchicalDataTemplate.ItemsSource != null && !base.HasNonDefaultValue(ItemsControl.ItemsSourceProperty))
                {
                    base.SetBinding(ItemsControl.ItemsSourceProperty, hierarchicalDataTemplate.ItemsSource);
                }
                if (hierarchicalDataTemplate.IsItemStringFormatSet && base.ItemStringFormat == parentItemsControl.ItemStringFormat)
                {
                    base.ClearValue(ItemsControl.ItemTemplateProperty);
                    base.ClearValue(ItemsControl.ItemTemplateSelectorProperty);
                    base.ClearValue(ItemsControl.ItemStringFormatProperty);
                    bool flag3 = hierarchicalDataTemplate.ItemStringFormat != null;
                    if (flag3)
                    {
                        base.ItemStringFormat = hierarchicalDataTemplate.ItemStringFormat;
                    }
                }
                if (hierarchicalDataTemplate.IsItemTemplateSelectorSet && base.ItemTemplateSelector == parentItemsControl.ItemTemplateSelector)
                {
                    base.ClearValue(ItemsControl.ItemTemplateProperty);
                    base.ClearValue(ItemsControl.ItemTemplateSelectorProperty);
                    bool flag4 = hierarchicalDataTemplate.ItemTemplateSelector != null;
                    if (flag4)
                    {
                        base.ItemTemplateSelector = hierarchicalDataTemplate.ItemTemplateSelector;
                    }
                }
                if (hierarchicalDataTemplate.IsItemTemplateSet && flag)
                {
                    base.ClearValue(ItemsControl.ItemTemplateProperty);
                    bool flag5 = hierarchicalDataTemplate.ItemTemplate != null;
                    if (flag5)
                    {
                        base.ItemTemplate = hierarchicalDataTemplate.ItemTemplate;
                    }
                }
                if (hierarchicalDataTemplate.IsItemContainerStyleSelectorSet && base.ItemContainerStyleSelector == parentItemsControl.ItemContainerStyleSelector)
                {
                    base.ClearValue(ItemsControl.ItemContainerStyleProperty);
                    base.ClearValue(ItemsControl.ItemContainerStyleSelectorProperty);
                    bool flag6 = hierarchicalDataTemplate.ItemContainerStyleSelector != null;
                    if (flag6)
                    {
                        base.ItemContainerStyleSelector = hierarchicalDataTemplate.ItemContainerStyleSelector;
                    }
                }
                if (hierarchicalDataTemplate.IsItemContainerStyleSet && flag2)
                {
                    base.ClearValue(ItemsControl.ItemContainerStyleProperty);
                    bool flag7 = hierarchicalDataTemplate.ItemContainerStyle != null;
                    if (flag7)
                    {
                        base.ItemContainerStyle = hierarchicalDataTemplate.ItemContainerStyle;
                    }
                }
                if (hierarchicalDataTemplate.IsAlternationCountSet && base.AlternationCount == parentItemsControl.AlternationCount)
                {
                    base.ClearValue(ItemsControl.AlternationCountProperty);
                    bool flag8 = true;
                    if (flag8)
                    {
                        base.AlternationCount = hierarchicalDataTemplate.AlternationCount;
                    }
                }
                if (hierarchicalDataTemplate.IsItemBindingGroupSet && base.ItemBindingGroup == parentItemsControl.ItemBindingGroup)
                {
                    base.ClearValue(ItemsControl.ItemBindingGroupProperty);
                    bool flag9 = hierarchicalDataTemplate.ItemBindingGroup != null;
                    if (flag9)
                    {
                        base.ItemBindingGroup = hierarchicalDataTemplate.ItemBindingGroup;
                    }
                }
            }
        }
예제 #25
0
        /// <summary>
        /// Prepare a PrepareHeaderedItemsControlContainer container for an
        /// item.
        /// </summary>
        /// <param name="control">Container to prepare.</param>
        /// <param name="item">Item to be placed in the container.</param>
        /// <param name="parentItemsControl">The parent ItemsControl.</param>
        /// <param name="parentItemContainerStyle">
        /// The ItemContainerStyle for the parent ItemsControl.
        /// </param>
        private static void PrepareHeaderedItemsControlContainer(HeaderedItemsControl control, object item, ItemsControl parentItemsControl, Style parentItemContainerStyle)
        {
            if (control != item)
            {
                // Copy the ItemsControl properties from parent to child
                DataTemplate parentItemTemplate = parentItemsControl.ItemTemplate;
                if (parentItemTemplate != null)
                {
                    control.SetValue(HeaderedItemsControl.ItemTemplateProperty, parentItemTemplate);
                }
                if (parentItemContainerStyle != null && HasDefaultValue(control, HeaderedItemsControl.ItemContainerStyleProperty))
                {
                    control.SetValue(HeaderedItemsControl.ItemContainerStyleProperty, parentItemContainerStyle);
                }

                // Copy the Header properties from parent to child
                if (control.HeaderIsItem || HasDefaultValue(control, HeaderedItemsControl.HeaderProperty))
                {
                    control.Header       = item;
                    control.HeaderIsItem = true;
                }
                if (parentItemTemplate != null)
                {
                    control.SetValue(HeaderedItemsControl.HeaderTemplateProperty, parentItemTemplate);
                }
                if (parentItemContainerStyle != null && control.Style == null)
                {
                    control.SetValue(HeaderedItemsControl.StyleProperty, parentItemContainerStyle);
                }

                // Note: this is where we would apply the HeaderTemplateSelector
                // (if implemented) or attempt to lookup the implicit template
                // for the type of the item if the headerTemplate were null.

                // Setup a hierarchical template
                HierarchicalDataTemplate headerTemplate = parentItemTemplate as HierarchicalDataTemplate;
                if (headerTemplate != null)
                {
                    if (headerTemplate.ItemsSource != null && HasDefaultValue(control, HeaderedItemsControl.ItemsSourceProperty))
                    {
                        control.SetBinding(
                            HeaderedItemsControl.ItemsSourceProperty,
                            new Binding
                        {
                            Converter          = headerTemplate.ItemsSource.Converter,
                            ConverterLanguage  = headerTemplate.ItemsSource.ConverterLanguage,
                            ConverterParameter = headerTemplate.ItemsSource.ConverterParameter,
                            Mode   = headerTemplate.ItemsSource.Mode,
                            Path   = headerTemplate.ItemsSource.Path,
                            Source = control.Header,
                        });
                    }
                    if (headerTemplate.IsItemTemplateSet && control.ItemTemplate == parentItemTemplate)
                    {
                        control.ClearValue(HeaderedItemsControl.ItemTemplateProperty);
                        if (headerTemplate.ItemTemplate != null)
                        {
                            control.ItemTemplate = headerTemplate.ItemTemplate;
                        }
                    }
                    if (headerTemplate.IsItemContainerStyleSet && control.ItemContainerStyle == parentItemContainerStyle)
                    {
                        control.ClearValue(HeaderedItemsControl.ItemContainerStyleProperty);
                        if (headerTemplate.ItemContainerStyle != null)
                        {
                            control.ItemContainerStyle = headerTemplate.ItemContainerStyle;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Default Constructor
        /// </summary>
        public Favourites()
        {
            InitializeComponent();

            UpdateButtonStates();

            treeView.StartDrag    += new DragDropTreeView.StartDragEventHandler(treeView_StartDrag);
            treeView.MoveToParent += new DragDropTreeView.MoveToParentEventHandler(treeView_MoveToParent);

            // Since HierarchicalDataTemplate is in a different namespace in WPF and silverlight
            // we created the wpf version using a factory, we also do this because an exception
            // is thrown by wpf if we try and pass it the DragDropTreeViewItemTemplate

#if SILVERLIGHT
            treeView.ItemTemplate = Resources["FavouritesHierarchicalDataTemplate"] as DragDropTreeViewItemTemplate;
#else
            HierarchicalDataTemplate hdt = new HierarchicalDataTemplate();
            hdt.ItemsSource = new System.Windows.Data.Binding("Children");

            FrameworkElementFactory contentControlFactory = new FrameworkElementFactory(typeof(ContentControl));
            contentControlFactory.AddHandler(ContentControl.MouseDoubleClickEvent, new MouseButtonEventHandler(treeViewItem_MouseDoubleClick));

            FrameworkElementFactory gridFactory = new FrameworkElementFactory(typeof(Grid));

            FrameworkElementFactory columnDefinition1Factory = new FrameworkElementFactory(typeof(ColumnDefinition));
            FrameworkElementFactory columnDefinition2Factory = new FrameworkElementFactory(typeof(ColumnDefinition));
            FrameworkElementFactory columnDefinition3Factory = new FrameworkElementFactory(typeof(ColumnDefinition));

            columnDefinition1Factory.SetValue(ColumnDefinition.WidthProperty, new GridLength(32));
            columnDefinition2Factory.SetValue(ColumnDefinition.WidthProperty, new GridLength(1, GridUnitType.Star));
            columnDefinition3Factory.SetValue(ColumnDefinition.WidthProperty, new GridLength(1, GridUnitType.Star));

            contentControlFactory.AppendChild(gridFactory);

            gridFactory.AppendChild(columnDefinition1Factory);
            gridFactory.AppendChild(columnDefinition2Factory);
            gridFactory.AppendChild(columnDefinition3Factory);

            FrameworkElementFactory imageFactory = new FrameworkElementFactory(typeof(Image));
            imageFactory.SetValue(Image.WidthProperty, 32.0);
            imageFactory.SetValue(Image.HeightProperty, 32.0);

            System.Windows.Data.Binding sourceBinding = new System.Windows.Data.Binding();
            sourceBinding.Converter = Resources["FavouriteIconConverter"] as System.Windows.Data.IValueConverter;
            imageFactory.SetBinding(Image.SourceProperty, sourceBinding);

            FrameworkElementFactory textBlock1 = new FrameworkElementFactory(typeof(TextBlock));
            textBlock1.SetValue(TextBlock.ForegroundProperty, new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF)));
            textBlock1.SetValue(Grid.ColumnProperty, 1);
            textBlock1.SetValue(TextBlock.MarginProperty, new Thickness(5, 0, 5, 0));
            textBlock1.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
            textBlock1.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding("Name"));

            FrameworkElementFactory textBlock2 = new FrameworkElementFactory(typeof(TextBlock));
            textBlock2.SetValue(TextBlock.ForegroundProperty, new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF)));
            textBlock2.SetValue(Grid.ColumnProperty, 2);
            textBlock2.SetValue(TextBlock.MarginProperty, new Thickness(5, 0, 5, 0));
            textBlock2.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);

            System.Windows.Data.Binding informationBinding = new System.Windows.Data.Binding();
            informationBinding.Converter = Resources["FavouriteNameConverter"] as System.Windows.Data.IValueConverter;
            textBlock2.SetBinding(TextBlock.TextProperty, informationBinding);

            gridFactory.AppendChild(imageFactory);
            gridFactory.AppendChild(textBlock1);
            gridFactory.AppendChild(textBlock2);

            hdt.VisualTree = contentControlFactory;

            treeView.ItemTemplate = hdt;
#endif
        }
예제 #27
0
 public static void SetHierarchicalTemplate(DependencyObject obj, HierarchicalDataTemplate value)
 {
     obj.SetValue(HierarchicalTemplateProperty, value);
 }
예제 #28
0
        private static bool _SearchDictionary(ResourceDictionary resources, Type key, out HierarchicalDataTemplate template)
        {
            var resourceKey = resources.Keys.OfType <DataTemplateKey>().FirstOrDefault(k => (Type)k.DataType == key);

            if (resourceKey != null)
            {
                template = resources[resourceKey] as HierarchicalDataTemplate;
                return(true);
            }
            foreach (var source in resources.MergedDictionaries)
            {
                if (_SearchDictionary(source, key, out template))
                {
                    return(true);
                }
            }
            template = null;
            return(false);
        }
예제 #29
0
        // As a convenience for hierarchical data, get the header template and
        // if it's a HierarchicalDataTemplate, set the ItemsSource, ItemTemplate,
        // ItemTemplateSelector, and ItemStringFormat properties from the template.
        void PrepareHierarchy(object item, ItemsControl parentItemsControl)
        {
            // get the effective header template
            DataTemplate headerTemplate = HeaderTemplate;

            if (headerTemplate == null)
            {
                DataTemplateSelector selector = HeaderTemplateSelector;
                if (selector != null)
                {
                    headerTemplate = selector.SelectTemplate(item, this);
                }

                if (headerTemplate == null)
                {
                    headerTemplate = (DataTemplate)FindTemplateResourceInternal(this, item, typeof(DataTemplate));
                }
            }

            // if the effective template is a HierarchicalDataTemplate, forward
            // the special properties
            HierarchicalDataTemplate hTemplate = headerTemplate as HierarchicalDataTemplate;

            if (hTemplate != null)
            {
                bool templateMatches       = (ItemTemplate == parentItemsControl.ItemTemplate);
                bool containerStyleMatches = (ItemContainerStyle == parentItemsControl.ItemContainerStyle);

                if (hTemplate.ItemsSource != null && !HasNonDefaultValue(ItemsSourceProperty))
                {
                    SetBinding(ItemsSourceProperty, hTemplate.ItemsSource);
                }

                if (hTemplate.IsItemStringFormatSet && ItemStringFormat == parentItemsControl.ItemStringFormat)
                {
                    // if the HDT defines a string format, turn off the
                    // forwarding of ItemTemplate[Selector] (which would get in the way).
                    ClearValue(ItemTemplateProperty);
                    ClearValue(ItemTemplateSelectorProperty);

                    // forward the HDT's string format
                    ClearValue(ItemStringFormatProperty);
                    bool setItemStringFormat = (hTemplate.ItemStringFormat != null);
                    if (setItemStringFormat)
                    {
                        ItemStringFormat = hTemplate.ItemStringFormat;
                    }
                }

                if (hTemplate.IsItemTemplateSelectorSet && ItemTemplateSelector == parentItemsControl.ItemTemplateSelector)
                {
                    // if the HDT defines a template selector, turn off the
                    // forwarding of ItemTemplate (which would get in the way).
                    ClearValue(ItemTemplateProperty);

                    // forward the HDT's template selector
                    ClearValue(ItemTemplateSelectorProperty);
                    bool setItemTemplateSelector = (hTemplate.ItemTemplateSelector != null);
                    if (setItemTemplateSelector)
                    {
                        ItemTemplateSelector = hTemplate.ItemTemplateSelector;
                    }
                }

                if (hTemplate.IsItemTemplateSet && templateMatches)
                {
                    // forward the HDT's template
                    ClearValue(ItemTemplateProperty);
                    bool setItemTemplate = (hTemplate.ItemTemplate != null);
                    if (setItemTemplate)
                    {
                        ItemTemplate = hTemplate.ItemTemplate;
                    }
                }

                if (hTemplate.IsItemContainerStyleSelectorSet && ItemContainerStyleSelector == parentItemsControl.ItemContainerStyleSelector)
                {
                    // if the HDT defines a container-style selector, turn off the
                    // forwarding of ItemContainerStyle (which would get in the way).
                    ClearValue(ItemContainerStyleProperty);

                    // forward the HDT's container-style selector
                    ClearValue(ItemContainerStyleSelectorProperty);
                    bool setItemContainerStyleSelector = (hTemplate.ItemContainerStyleSelector != null);
                    if (setItemContainerStyleSelector)
                    {
                        ItemContainerStyleSelector = hTemplate.ItemContainerStyleSelector;
                    }
                }

                if (hTemplate.IsItemContainerStyleSet && containerStyleMatches)
                {
                    // forward the HDT's container style
                    ClearValue(ItemContainerStyleProperty);
                    bool setItemContainerStyle = (hTemplate.ItemContainerStyle != null);
                    if (setItemContainerStyle)
                    {
                        ItemContainerStyle = hTemplate.ItemContainerStyle;
                    }
                }

                if (hTemplate.IsAlternationCountSet && AlternationCount == parentItemsControl.AlternationCount)
                {
                    // forward the HDT's alternation count
                    ClearValue(AlternationCountProperty);
                    bool setAlternationCount = true;
                    if (setAlternationCount)
                    {
                        AlternationCount = hTemplate.AlternationCount;
                    }
                }

                if (hTemplate.IsItemBindingGroupSet && ItemBindingGroup == parentItemsControl.ItemBindingGroup)
                {
                    // forward the HDT's ItemBindingGroup
                    ClearValue(ItemBindingGroupProperty);
                    bool setItemBindingGroup = (hTemplate.ItemBindingGroup != null);
                    if (setItemBindingGroup)
                    {
                        ItemBindingGroup = hTemplate.ItemBindingGroup;
                    }
                }
            }
        }