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


C# FrameworkElement.InvalidateMeasure方法代码示例

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


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

示例1: DoTemplateInvalidations


//.........这里部分代码省略.........
            {
                //
                // Template is changing
                //

                // Set up any per-instance state relating to the new Template
                // We do this here instead of OnTemplateInvalidated because
                // this needs to happen for the *first* Template.
                StyleHelper.UpdateInstanceData(
                    StyleHelper.TemplateDataField,
                    feContainer /* fe */, null /* fce */,
                    null /*oldStyle */, null /* newStyle */,
                    oldFrameworkTemplate, newFrameworkTemplate,
                    InternalFlags.HasTemplateGeneratedSubTree);

                // If this new template has resource references (either for the container
                // or for children in the visual tree), then, mark it so that it will
                // not be ignored during resource change invalidations
                if (newTemplate != null && newTemplateHasResourceReferences)
                {
                    Debug.Assert(feContainer != null);
                    feContainer.HasResourceReference = true;
                }

                // If the template wants to watch for the Loaded and/or Unloaded events, set the
                // flag that says we want to receive it.  Otherwise, if it was set in the old template, clear it.

                UpdateLoadedFlag( container, oldFrameworkTemplate, newFrameworkTemplate );


                // Wipe out VisualTree only if VisualTree factories
                // are changing
                //
                // If the factories are null for both new and old, then, the Template
                // has the opportunity to supply the VisualTree using the "BuildVisualTree"
                // virtual.
                FrameworkElementFactory              oldFactory;
                FrameworkElementFactory              newFactory;
                bool                                 canBuildVisualTree;
                bool                                 hasTemplateGeneratedSubTree;
                FrugalStructList<ContainerDependent> oldContainerDependents;
                FrugalStructList<ContainerDependent> newContainerDependents;

                Debug.Assert(feContainer != null);
                oldFactory = (oldFrameworkTemplate != null) ? oldFrameworkTemplate.VisualTree : null;
                newFactory = (newFrameworkTemplate != null) ? newFrameworkTemplate.VisualTree : null;

                canBuildVisualTree = (oldFrameworkTemplate != null) ? oldFrameworkTemplate.CanBuildVisualTree : false;
                hasTemplateGeneratedSubTree = feContainer.HasTemplateGeneratedSubTree;
                oldContainerDependents = (oldFrameworkTemplate != null) ? oldFrameworkTemplate.ContainerDependents : StyleHelper.EmptyContainerDependents;
                newContainerDependents = (newFrameworkTemplate != null) ? newFrameworkTemplate.ContainerDependents : StyleHelper.EmptyContainerDependents;

                if (hasTemplateGeneratedSubTree)
                {
                    StyleHelper.ClearGeneratedSubTree(oldTemplateData,
                        feContainer /* fe */, null /* fce */,
                        oldFrameworkTemplate );
                }

                // Propagate invalidation for template dependents
                FrugalStructList<ContainerDependent> exclusionContainerDependents =
                    new FrugalStructList<ContainerDependent>();
                StyleHelper.InvalidateContainerDependents(container,
                    ref exclusionContainerDependents,
                    ref oldContainerDependents,
                    ref newContainerDependents);

                // Propagate invalidation for resource references that may be
                // picking stuff from the style's ResourceDictionary
                DoTemplateResourcesInvalidations(container, feContainer, null /*fce*/, oldTemplate, newTemplate);

                Debug.Assert(feContainer != null);
                feContainer.OnTemplateChangedInternal(oldFrameworkTemplate, newFrameworkTemplate);
            }
            else
            {
                //
                // Template is not changing
                //

                // Template was invalidated but didn't change. If the Template created the
                // VisualTree via an override of BuildVisualTree, then, it is
                // wiped out now so that it may be conditionally rebuilt by the
                // custom Template
                if (newFrameworkTemplate != null)
                {
                    if (feContainer.HasTemplateGeneratedSubTree
                        && newFrameworkTemplate.VisualTree == null
                        && !newFrameworkTemplate.HasXamlNodeContent )
                    {
                        StyleHelper.ClearGeneratedSubTree(oldTemplateData, feContainer /* fe */, null /* fce */,
                            oldFrameworkTemplate);

                        // Nothing guarantees that ApplyTemplate actually gets
                        // called, so ask for it explicitly (bug 963163).
                        feContainer.InvalidateMeasure();
                    }
                }
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:101,代码来源:StyleHelper.cs

示例2: Resize_Item

        protected void Resize_Item(FrameworkElement item, Point position)
        {
            if (position.X < 0 || position.Y < 0)
                return;

            item.Width = Calculate_Discrete_X(position.X);
            item.Height = Calculate_Discrete_Y(position.Y);
            item.InvalidateMeasure();
        }
开发者ID:valeriob,项目名称:Routing,代码行数:9,代码来源:PagedWidgetContainer.xaml.cs

示例3: GenerateImage

        public static BitmapImage GenerateImage(FrameworkElement pFE, int pWidth, int pHeight)
        {;
            pFE.Width = pWidth;
            pFE.Height = pHeight;
            System.Windows.Size theTargetSize = new System.Windows.Size(pWidth, pHeight);
            pFE.Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity));
            pFE.Arrange(new Rect(theTargetSize));
            // to affect the changes in the UI, you must call this method at the end to apply the new changes

            pFE.UpdateLayout();
            pFE.InvalidateMeasure();
            pFE.InvalidateArrange();
            pFE.InvalidateVisual();
            var imgEncoder = new PngBitmapEncoder();
            imgEncoder.Interlace = PngInterlaceOption.Off;
            RenderTargetBitmap bmpSource = new RenderTargetBitmap((int)pWidth, (int)pHeight, 96, 96, PixelFormats.Pbgra32);
            bmpSource.Render(pFE);
            imgEncoder.Frames.Add(BitmapFrame.Create(bmpSource));
            BitmapImage result = new BitmapImage();
            using (var stream = new MemoryStream())
            {
                imgEncoder.Save(stream);
                stream.Seek(0, SeekOrigin.Begin);

                
                
                result.BeginInit();
                // According to MSDN, "The default OnDemand cache option retains access to the stream until the image is needed."
                // Force the bitmap to load right now so we can dispose the stream.
                result.CacheOption = BitmapCacheOption.OnLoad;
                result.StreamSource = stream;
                result.EndInit();
              //  result.Freeze();
                
            }

            return result;


        }
开发者ID:TNOCS,项目名称:csTouch,代码行数:40,代码来源:MgrsEsriLayer.cs


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