Beispiel #1
0
        //-------------------------------------------------------------------
        //
        //  Internal Methods
        //
        //-------------------------------------------------------------------

        //
        // ProcessTemplateBeforeSeal
        //
        // This is used in the case of templates defined with FEFs.  For templates
        // in Baml (the typical case), see the OnApply override.
        //
        // 1. Verify that
        //      a. root element is a Panel
        // 2. Set IsItemsHost = true
        //

        internal override void ProcessTemplateBeforeSeal()
        {
            FrameworkElementFactory root;

            if (HasContent)
            {
                // This is a Baml-style template

                // Validate the root type (it must be a Panel)

                TemplateContent      templateHolder = Template as TemplateContent;
                System.Xaml.XamlType panelType      = templateHolder.SchemaContext.GetXamlType(typeof(Panel));
                if (templateHolder.RootType == null || !templateHolder.RootType.CanAssignTo(panelType))
                {
                    throw new InvalidOperationException(SR.Get(SRID.ItemsPanelNotAPanel, templateHolder.RootType));
                }
            }

            else if ((root = this.VisualTree) != null)
            {
                // This is a FEF-style template
                if (!typeof(Panel).IsAssignableFrom(root.Type))
                {
                    throw new InvalidOperationException(SR.Get(SRID.ItemsPanelNotAPanel, root.Type));
                }

                root.SetValue(Panel.IsItemsHostProperty, true);
            }
        }
Beispiel #2
0
        // workaround, pending bug 953483.  The panel is
        // being removed from the tree, so it should release
        // its resources (chiefly - stop listening for generator's
        // ItemsChanged event).  Until there's a mechanism for
        // this, just mark the panel as a non-ItemsHost, so
        // that the next time it gets ItemsChanged it will
        // stop listening.  (See also bug 942265)
        private void ClearPanel()
        {
            Panel oldPanel = (this.VisualChildrenCount > 0) ? this.GetVisualChild(0) as Panel : null;
            Type  type     = null;

            if (Template != null)
            {
                // Get the type of the template content's root

                // Is this a FEF-based template?
                if (Template.VisualTree != null)
                {
                    type = Template.VisualTree.Type;
                }

                // Or, is it a (non-empty) Baml-based template?
                else if (Template.HasXamlNodeContent)
                {
                    System.Xaml.XamlType xType = (Template.Template as TemplateContent).RootType;
                    type = xType.UnderlyingType;
                }
            }

            if (oldPanel != null && oldPanel.GetType() == type)
            {
                oldPanel.IsItemsHost = false;
            }
        }