Exemple #1
0
        internal static void OnCacheModeChanged(Object sender, DependencyPropertyChangedEventArgs e)
        {
            Viewport2DVisual3D viewport2DVisual3D = ((Viewport2DVisual3D)sender);

            BitmapCache oldValue = (CacheMode)e.OldValue as BitmapCache;
            BitmapCache newValue = (CacheMode)e.NewValue as BitmapCache;

            if (oldValue != newValue)
            {
                viewport2DVisual3D.InternalBitmapCacheBrush.BitmapCache = newValue;

                //
                // The BitmapCacheBrush doesn't point directly at the Visual like the VisualBrush does,
                // since BitmapCacheBrush ignores most properties on a Visual by design.  In order for
                // those properties to be respected to match the internal VisualBrush's behavior, we insert
                // a dummy Visual node between the V2DV3D and its 2D Visual.  We then target the dummy
                // node with the brush instead.
                //

                if (oldValue == null)
                {
                    //
                    // If we are swapping from using the VisualBrush to using the BitmapCacheBrush...
                    //

                    // Remove the visual child from the V2DV3D and add the dummy child.
                    viewport2DVisual3D.RemoveVisualChild(viewport2DVisual3D.Visual);
                    viewport2DVisual3D.AddVisualChild(viewport2DVisual3D.InternalBitmapCacheBrush.InternalTarget);

                    Debug.Assert((viewport2DVisual3D.InternalBitmapCacheBrush.InternalTarget == null ||
                                  viewport2DVisual3D.InternalBitmapCacheBrush.InternalTarget.InheritanceContext == null),
                                 "Expected AddVisualChild to remove the InheritanceContext on InternalTarget");

                    // Swap the brush pointing to the visual.  The cache brush will re-parent the visual to the dummy.
                    viewport2DVisual3D.InternalVisualBrush.Visual      = null;
                    viewport2DVisual3D.InternalBitmapCacheBrush.Target = viewport2DVisual3D.Visual;

                    // setting the cache brush to use this new child should not invalidate our previous condition
                    Debug.Assert((viewport2DVisual3D.InternalBitmapCacheBrush.InternalTarget == null ||
                                  viewport2DVisual3D.InternalBitmapCacheBrush.InternalTarget.InheritanceContext == null),
                                 "Expected the InternalBitmapCacheBrush not to set the InheritanceContext");
                }

                if (newValue == null)
                {
                    //
                    // If we are swapping from using the BitmapCacheBrush to using the VisualBrush...
                    //

                    // Swap the brush pointing to the visual.  The cache brush will remove the dummy as the parent
                    // of the visual.
                    viewport2DVisual3D.InternalBitmapCacheBrush.Target = null;
                    viewport2DVisual3D.InternalVisualBrush.Visual      = viewport2DVisual3D.Visual;

                    // Remove the dummy child and re-add the visual as the V2DV3D's child.
                    viewport2DVisual3D.RemoveVisualChild(viewport2DVisual3D.InternalBitmapCacheBrush.InternalTarget);
                    viewport2DVisual3D.AddVisualChild(viewport2DVisual3D.Visual);

                    Debug.Assert((viewport2DVisual3D.Visual == null || viewport2DVisual3D.Visual.InheritanceContext == null),
                                 "Expected AddVisualChild to remove the InheritanceContext on Visual");
                }

                // If we changed from using one brush to the other we need to regenerate the Material.
                if (oldValue == null || newValue == null)
                {
                    viewport2DVisual3D.GenerateMaterial();
                }
            }
        }
Exemple #2
0
        internal static void OnMaterialPropertyChanged(Object sender, DependencyPropertyChangedEventArgs e)
        {
            Viewport2DVisual3D viewport2DVisual3D = ((Viewport2DVisual3D)sender);

            viewport2DVisual3D.GenerateMaterial();
        }