当前位置: 首页>>代码示例>>C#>>正文


C# FrameworkElementFactory.InstantiateTree方法代码示例

本文整理汇总了C#中System.Windows.FrameworkElementFactory.InstantiateTree方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElementFactory.InstantiateTree方法的具体用法?C# FrameworkElementFactory.InstantiateTree怎么用?C# FrameworkElementFactory.InstantiateTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.FrameworkElementFactory的用法示例。


在下文中一共展示了FrameworkElementFactory.InstantiateTree方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ApplyTemplateContent

        //+----------------------------------------------------------------------------------
        //
        //  ApplyTemplateContent
        //
        //  Instantiate the content of the template (either from FEFs or from Baml).
        //  This is done for every element to which this template is attached.
        //
        //+----------------------------------------------------------------------------------
        #region InstantiateSubTree

        //[CodeAnalysis("AptcaMethodsShouldOnlyCallAptcaMethods")] //Tracking Bug: 29647
        internal static bool ApplyTemplateContent(
            UncommonField<HybridDictionary[]>  dataField,
            DependencyObject            container,
            FrameworkElementFactory     templateRoot,
            int                         lastChildIndex,
            HybridDictionary            childIndexFromChildID,
            FrameworkTemplate           frameworkTemplate)
        {
            Debug.Assert(frameworkTemplate != null );

            bool visualsCreated = false;

            FrameworkElement feContainer = container as FrameworkElement;

            // Is this a FEF-style template?

            if (templateRoot != null)
            {
                // Yes, we'll instantiate from a FEF tree.

                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose, EventTrace.Event.WClientParseInstVisTreeBegin);

                CheckForCircularReferencesInTemplateTree(container, frameworkTemplate );

                // Container is considered ChildIndex '0' (Self), but,
                // Container.ChildIndex isn't set
                List<DependencyObject> affectedChildren = new List<DependencyObject>(lastChildIndex);

                // Assign affectedChildren to container
                TemplatedFeChildrenField.SetValue(container, affectedChildren);

                // When building the template children chain, we keep a chain of
                // nodes that don't need to be in the chain for property invalidation
                // or lookup purposes.  (And hence not assigned a TemplateChildIndex)
                // We only need them in order to clean up their _templatedParent
                // references (see FrameworkElement.ClearTemplateChain)
                List<DependencyObject> noChildIndexChildren = null;

                // Instantiate template
                // Setup container's reference to first child in chain
                // and add to tree
                DependencyObject treeRoot = templateRoot.InstantiateTree(
                    dataField,
                    container,
                    container,
                    affectedChildren,
                    ref noChildIndexChildren,
                    ref frameworkTemplate.ResourceDependents);

                Debug.Assert(treeRoot is FrameworkElement || treeRoot is FrameworkContentElement,
                    "Root node of tree must be a FrameworkElement or FrameworkContentElement.  This should have been caught by set_VisualTree" );

                // From childFirst to childLast is the chain of child nodes with
                //  childIndex.  Append that chain with the chain of child nodes
                //  with no childIndex assigned.
                if( noChildIndexChildren != null )
                {
                    affectedChildren.AddRange(noChildIndexChildren);
                }

                visualsCreated = true;

                if (feContainer != null && EventTrace.IsEnabled(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose))
                {
                    string label = feContainer.Name;
                    if (label == null || label.Length == 0)
                        label = container.GetHashCode().ToString(System.Globalization.CultureInfo.InvariantCulture);

                    EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientParseInstVisTreeEnd, EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose,
                                                         String.Format(System.Globalization.CultureInfo.InvariantCulture, "Style.InstantiateSubTree for {0} {1}", container.GetType().Name, label));
                }
            }

            // It's not a FEF-style template, is it a non-empty optimized one?

            else if (frameworkTemplate != null && frameworkTemplate.HasXamlNodeContent)
            {
                // Yes, create from the optimized template content.
                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose, EventTrace.Event.WClientParseInstVisTreeBegin);

                CheckForCircularReferencesInTemplateTree(container, frameworkTemplate );

                // Container is considered ChildIndex '0' (Self), but,
                // Container.ChildIndex isn't set

                List<DependencyObject> affectedChildren = new List<DependencyObject>(lastChildIndex);

                // Assign affectedChildren to container

//.........这里部分代码省略.........
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:101,代码来源:StyleHelper.cs


注:本文中的System.Windows.FrameworkElementFactory.InstantiateTree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。